converting byte array to float


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: converting byte array to float

  1. #1
    Curtis Nelson Guest

    converting byte array to float


    Hi,

    Can somebody please supply me with some code to convert a 4-byte array into
    a float? In C, you can just cast a float pointer to the byte pointer, but
    no such mechanism exists in Java.

    Thanks


  2. #2
    Paul Clapham Guest

    Re: converting byte array to float

    DataInputStream dis = new DataInputStream(new
    ByteArrayInputStream(the4byteArray));
    float f = dis.readFloat();

    However, if you originally read the 4 bytes from a file or some other input
    stream, why not go back and change your program to read the float number
    directly from that source? Wrap your input stream in a DataInputStream as
    in the code above.

    PC2

    "Curtis Nelson" <curtis_nelson@@larsondavis.com> wrote in message
    news:3ac258bb$1@news.devx.com...
    >
    > Hi,
    >
    > Can somebody please supply me with some code to convert a 4-byte array

    into
    > a float? In C, you can just cast a float pointer to the byte pointer, but
    > no such mechanism exists in Java.
    >
    > Thanks
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center