[953] in java-interest

home help back first fref pref prev next nref lref last post

How to convert bytes to a float?

daemon@ATHENA.MIT.EDU (SMATHUR.US.ORACLE.COM)
Tue Aug 15 21:05:28 1995

Date: 15 Aug 95 14:31:49 -0700
From: "SMATHUR.US.ORACLE.COM" <SMATHUR@us.oracle.com>
To: java-interest@java.sun.com


I have a server program that is sending a block of data that 
has binary encoded data.  I have written some Java code that 
can take the array of bytes and parse it back to Java ints 
(using b1+256*b2+512*b3+1024*b4) and Strings.  The server is 
sending floats as 4 bytes in IEEE format which is supposed to 
be compatible with Java floats.  The problem is that I have 
found NO library calls which will convert 4 bytes into a float 
(and vica versa).  This is easy in C/C++ by playing with pointers, 
but Java won't (correct me if I'm wrong) cast a array of bytes 
to a float (or vica versa).  I could cheat and do this with 
native methods, but that would'nt solve this problem elegantly. 
 
Does anyone know of a way to do this? How is the Datastream.readFloat() 
implemented in the source? 
 
Thanks in advance

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post