Big Endian float conversion

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 3
Reputation: piote is an unknown quantity at this point 
Solved Threads: 0
piote piote is offline Offline
Newbie Poster

Big Endian float conversion

 
0
  #1
Aug 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Big Endian float conversion

 
0
  #2
Aug 26th, 2007
1) Yeah, you can tell the BinaryReader what encoding to use with the System.Text.Encoding class.
  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.
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: piote is an unknown quantity at this point 
Solved Threads: 0
piote piote is offline Offline
Newbie Poster

Re: Big Endian float conversion

 
0
  #3
Aug 28th, 2007
Thanks for your help!

Regards,
Piote
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 3
Reputation: sidharthrshah is an unknown quantity at this point 
Solved Threads: 0
sidharthrshah sidharthrshah is offline Offline
Newbie Poster

Re: Big Endian float conversion

 
0
  #4
May 13th, 2008
And how do I convert it the other way round.

Regards,
Sidharth Shah.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC