| | |
Big Endian float conversion
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
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
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
1) Yeah, you can tell the BinaryReader what encoding to use with the System.Text.Encoding class.
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.
C# Syntax (Toggle Plain Text)
BinaryReader reader = new BinaryReader( stream, Encoding.BigEndianUnicode );
The truth does not change according to our ability to stomach it.
![]() |
Similar Threads
- StreamReader and Position (C#)
- StreamReader and Position (In VB) (VB.NET)
- Pascal -> C++; Binary, convert? (C++)
- passing data around (C)
- Doubts (Computer Science)
- Compression/Decompression Wave File to MP3 and Vice Versa (C++)
- Pounds to Grams Conversion (C++)
- Array limit (C)
Other Threads in the C# Forum
- Previous Thread: Tutorial request
- Next Thread: dotnetfx not working as prerequisite
| Thread Tools | Search this Thread |
.net access algorithm array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml





