Hello,
I need to support a file format that stores integers with the MSB first
and the LSB last. When I use
BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII);
int someValue = 1;
aWriter.WriteInt32(someValue);
the byte stream that appears in the file is
01 00 00 00
What I need for this file format is
00 00 00 01
There does not appear to be anything in Marshal that supports this. Does
anyone have a recommendation?
Thanks in advance,
--
PC 9 5939
On 2004-10-07, PHil Coveney <PH*********@discussions.microsoft.com> wrote: Hello,
I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
Thanks in advance,
You could try using System.Net.IPAddress.HostToNetworkOrder to convert
the integer first....
using System;
using System.Net;
public class test
{
public static void Main ()
{
int i = 1;
int j = IPAddress.HostToNetworkOrder (i);
Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (i)));
Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (j)));
}
}
--
Tom Shelton [MVP]
On 2004-10-07, PHil Coveney <PH*********@discussions.microsoft.com> wrote: Hello,
I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
Thanks in advance,
You could try using System.Net.IPAddress.HostToNetworkOrder to convert
the integer first....
using System;
using System.Net;
public class test
{
public static void Main ()
{
int i = 1;
int j = IPAddress.HostToNetworkOrder (i);
Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (i)));
Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (j)));
}
}
--
Tom Shelton [MVP]
You can also do by yourself with some bit shifting:
public void WriteInt32BigEndian ( int value )
{
base.Write( new byte [0x4] {
(byte) (value >> 0x18),
(byte) (value >> 0x10),
(byte) (value >> 0x8),
(byte) (value)
} );
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... On 2004-10-07, PHil Coveney <PH*********@discussions.microsoft.com> wrote: Hello,
I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
Thanks in advance,
You could try using System.Net.IPAddress.HostToNetworkOrder to convert the integer first....
using System; using System.Net;
public class test { public static void Main () { int i = 1; int j = IPAddress.HostToNetworkOrder (i);
Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (i))); Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (j))); } }
-- Tom Shelton [MVP]
You can also do by yourself with some bit shifting:
public void WriteInt32BigEndian ( int value )
{
base.Write( new byte [0x4] {
(byte) (value >> 0x18),
(byte) (value >> 0x10),
(byte) (value >> 0x8),
(byte) (value)
} );
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... On 2004-10-07, PHil Coveney <PH*********@discussions.microsoft.com> wrote: Hello,
I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
Thanks in advance,
You could try using System.Net.IPAddress.HostToNetworkOrder to convert the integer first....
using System; using System.Net;
public class test { public static void Main () { int i = 1; int j = IPAddress.HostToNetworkOrder (i);
Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (i))); Console.WriteLine (BitConverter.ToString (BitConverter.GetBytes (j))); } }
-- Tom Shelton [MVP]
PHil Coveney <PH*********@discussions.microsoft.com> wrote: I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
You could use my EndianBinaryWriter which allows you to specify
endianness: http://www.pobox.com/~skeet/csharp/miscutil
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
PHil Coveney <PH*********@discussions.microsoft.com> wrote: I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
You could use my EndianBinaryWriter which allows you to specify
endianness: http://www.pobox.com/~skeet/csharp/miscutil
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
On Wed, 6 Oct 2004 23:43:01 -0700, PHil Coveney wrote: Hello,
I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
Thanks in advance,
In addition, check out the system.Text.Encoding.BigEndianUnicode encoding
method.
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Hi Jon,
Wow, I got several very helpful responses to this post...but yours, the
one that said "use this, it's already done," wins the prize. Thanks for your
help, and your DLL.
PC
"Jon Skeet [C# MVP]" wrote: PHil Coveney <PH*********@discussions.microsoft.com> wrote: I need to support a file format that stores integers with the MSB first and the LSB last. When I use BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII); int someValue = 1; aWriter.WriteInt32(someValue); the byte stream that appears in the file is 01 00 00 00
What I need for this file format is 00 00 00 01
There does not appear to be anything in Marshal that supports this. Does anyone have a recommendation?
You could use my EndianBinaryWriter which allows you to specify endianness:
http://www.pobox.com/~skeet/csharp/miscutil
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
PHil Coveney <PH*********@discussions.microsoft.com> wrote: Wow, I got several very helpful responses to this post...but yours, the one that said "use this, it's already done," wins the prize. Thanks for your help, and your DLL.
My pleasure - just let me know if you have any problems with it :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PHil Coveney |
last post by:
Hello,
I need to support a file format that stores integers with the MSB first
and the LSB last. When I use
BinaryWriter aWriter = new BinaryWriter(aFileStream, Encoding.ASCII);
int someValue...
|
by: Michi Henning |
last post by:
Looking at the language spec, I can't find a statement
about the byte order for value types, such as int, float,
etc. Are they guaranteed to be little-endian or big-
endian? I know that, on a...
|
by: homepricemaps |
last post by:
hey folks,
have a logic question for you. appreciate the help in advance.
i am scraping 3 pieces of information from the html namely the food
name , store name and price. and i am doing this...
|
by: mike7411 |
last post by:
Is there any easy way to reverse the order of the bits in a byte in
C++?
(i.e. 00000001 becomes 10000000)
|
by: aburningflame23 |
last post by:
alright this is my problem.....please help
i need to write a program that reads 10 integers from a file into an array and then prints out the numbers in reverse order. It also prints out the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |