943,829 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 6378
  • C# RSS
Aug 26th, 2007
0

Big Endian float conversion

Expand Post »
Hi,
I am trying to convert a Big Endian data file to something readable on most Windows PCs. I do ok with integer data but I cannot convert the floating points (32-bit IEEE).
1) Is it possible for a BinaryReader to account for Big Endian, such that .ReadSingle() would return the correct value?

2) If I have to read the bytes one at a time and reverse them, is there a way to type cast it to a float?

I pursued #2 for a while, but C# type-casting seems to convert the actual value and not the binary that represents it. So the result is something like 1.12E9 instead of 89.9.
I really don't know how to make it work correctly. I would be grateful for any help.

Regards,
Piote
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
piote is offline Offline
3 posts
since Aug 2007
Aug 26th, 2007
0

Re: Big Endian float conversion

1) Yeah, you can tell the BinaryReader what encoding to use with the System.Text.Encoding class.
C# Syntax (Toggle Plain Text)
  1. BinaryReader reader = new BinaryReader( stream, Encoding.BigEndianUnicode );
2) No, but you can use the System.BitConverter class to turn an array of bytes into whatever type it supports. And it supports both single and double precision floating point conversions.
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Aug 28th, 2007
0

Re: Big Endian float conversion

Thanks for your help!

Regards,
Piote
Reputation Points: 10
Solved Threads: 0
Newbie Poster
piote is offline Offline
3 posts
since Aug 2007
May 13th, 2008
0

Re: Big Endian float conversion

And how do I convert it the other way round.

Regards,
Sidharth Shah.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sidharthrshah is offline Offline
3 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Tutorial request
Next Thread in C# Forum Timeline: dotnetfx not working as prerequisite





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC