|
-
Aug 2nd, 2006, 08:25 AM
#1
Thread Starter
Addicted Member
Byte Order Question - How to reverse?
I'm creating a binary file using the binarywriter class. I'm writing decimal numbers to the file, each one as a 4 byte representation.
So, if I wanted to write the decimal number 10523
The hex would be 0x291B.
I need the bytes written to the file in this order:
0x1B 0x29 0x00 0x00
My problem is that using this code:
Code:
byte[] numBuffer = null;
decvalue = 10523;
numBuffer = System.Text.Encoding.ASCII.GetBytes(decvalue.ToString("x4"));
wrtBin.Write(numBuffer);
The bytes are written to the file in this order:
0x29 0x1b 0x00 0x00
What's the best way for me to do this?
-
Aug 2nd, 2006, 08:32 AM
#2
Re: Byte Order Question - How to reverse?
What is the logic you have for this reversal? What if it were a larger number like 0x23bdc5? Would you still just reverse the first two bytes?
-
Aug 2nd, 2006, 08:40 AM
#3
Thread Starter
Addicted Member
Re: Byte Order Question - How to reverse?
0x23bdc5 should be:
0xC5 0xBD 0x23 0x00
Also... He says that if I use my c# code and do this:
Code:
WriteFile( hf, ( BYTE *)&dwSomeDwordValue, sizeof( DWORD ), ... );
That the bytes will be written in the correct order. I have no clue how to do that in c# though.
-
Aug 2nd, 2006, 09:24 AM
#4
Re: Byte Order Question - How to reverse?
Alright, to reverse the array, you can use Array.Reverse(arrayname).
About WriteFile, what language is 'he' talking about? Here is .NET's WriteFile,
http://msdn.microsoft.com/library/de...efiletopic.asp
Maybe you're looking for one of these.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|