Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dumping Hex Data using BinaryWriter encoding it backwards

Status
Not open for further replies.

wbochar

IS-IT--Management
Mar 14, 2003
72
US
I'm exporting Hex values out to disk. Everytime I do it, it comes out backwards..

ulong [] FontData = new ulong[1];

private void writeData()
{
HexData[0]=0xCF1333373F43D7FF;
HexData[1]=0xCF1333373F43D7FF;

using (FileStream fs = new FileStream(@"c:\DATA.DAT",FileMode.Create,FileAccess.Write))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
foreach (ulong DataSegment in HexData)
{
bw.Write((ulong)DataSegment);
}
}
}


It dumps the data; but it comes out backwards (hexdump):

00000000h: FF D7 43 3F 37 33 13 CF FF D7 43 3F 37 33 13 CF ;

I've messed with the encoding on the binarywriter and nothing changes. Am I missing something?

Wolf
 
That would probably be correct. A ulong is 8 bytes and Intel CPUs use Little Endien order, ie lowest byte first.


Hope this helps.

[vampire][bat]
 
I'm aware of this; but I want to force use of a different order. I'm working on generating data files for other computer platforms that use the reverse ordering.

When
using (BinaryWriter bw = new BinaryWriter(fs))

you can specify the the different encodings.. but it seems to not make any difference.
 
Try using the IPAddress.NetworkToHostOrder() method to change the endianness of your number.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I'm using ulong's, the IPAdress.NetworkHostOrder maxed out long.

Any other ideas?
 
Not an ideal solution but, since you know that a ulong is 8 bytes why don't you read in as bytes and after every 8 bytes read, write them out (as bytes) in reverse order?


As I said, not an ideal solution, but it should do the trick.


Hope this helps.

[vampire][bat]
 
I was trying to avoid that; maybe there was something that I didn't see or was missing..

I've got the process working the manual byte re-ordering.

Thanks for the affirmation.
 
In your reply (1 Dec 06 9:50) you said: "you can specify the the different encodings.. but it seems to not make any difference."

As such I can't see any other solution (crude as it may be). Although, I would guess that behind the scenes, all that changing the encoding does is to manually turn the bytes around.


Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top