File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes convert byte[] to float Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "convert byte[] to float" Watch "convert byte[] to float" New topic
Author

convert byte[] to float

Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
I'm building an application that collects data over the serial port as a byte[]. I need to parse this array based upon a defined protocol. When it sends a float I get 4 bytes (4 * 8 = 32 bits). How would I convert these bytes into a single float value? Easy for integers...

Oops, never mind. I just found the answer posted earlier today (what a coincidence!)

ms
[ September 16, 2004: Message edited by: Mike Southgate ]

ms<br />SCJP, SCJD
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Did you read the javadocs for java.lang.Float.intBitsToFloat ()?
I would try with that and a lot of test values.


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: convert byte[] to float
 
Similar Threads
byte[] to float
long to byte array
io
long in a byte array
writing 4 byte little-endian long integers