Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Big versus little endian (byte order)

Reply
Thread Tools

Big versus little endian (byte order)

 
 
Gido
Guest
Posts: n/a
 
      07-05-2003
My questions is: How can I read little endian values from a file stream?

I am trying to read values from a binary file in the WINDOWS platform.
The file includes values of type integer (signed 32-bit integer - 4 bytes) and
double (signed 64-bit IEEE double-precision floating point numbers).
I am using the readInt() and readDouble() functions as defined in the
java.io.* package. However, the values are stored in big and little byte order.
The readInt() and readDouble() functions correctly return only the big endian
values.

My questions is: How can I read the little endian values?
 
Reply With Quote
 
 
 
 
xarax
Guest
Posts: n/a
 
      07-06-2003
(Gido) wrote in message news:<. com>...
> My questions is: How can I read little endian values from a file stream?
>
> I am trying to read values from a binary file in the WINDOWS platform.
> The file includes values of type integer (signed 32-bit integer - 4 bytes) and
> double (signed 64-bit IEEE double-precision floating point numbers).
> I am using the readInt() and readDouble() functions as defined in the
> java.io.* package. However, the values are stored in big and little byte order.
> The readInt() and readDouble() functions correctly return only the big endian
> values.
>
> My questions is: How can I read the little endian values?


The java.nio (new I/O) package that is new with jdk1.4 has ByteBuffer
and friends that support big and little endian. Use the new I/O
facilities.
 
Reply With Quote
 
 
 
 
Gido
Guest
Posts: n/a
 
      07-06-2003
Jon

Thanks a lot. Your information was exactly the jump start I needed.
From here on it will be easy.

Thanks
Gido


"Jon A. Cruz" <> wrote in message news:<>...
> Gido wrote:
> > My questions is: How can I read little endian values from a file stream?

>
> Either use someone else's class (like Roedy's LEDataStream
> http://mindprod.com/jgloss/ledatastream.html), or just do it yourself.
>
> Read 4 bytes. Shift and mask. Voila! You're done. It should end up
> looking just like the C/C++ code should.
>
>
> byte tmp[4] = {0,0,0,0};
> in.readFully( tmp );
> int val = ((0x0ff & tmp[0]) << 0)
> | ((0x0ff & tmp[1]) <<
> | ((0x0ff & tmp[2]) <<16)
> | ((0x0ff & tmp[3]) <<24);
>
>
>
> And to read a Double
>
> Read 8 bytes.
> Pack them back into a long. Just like that int code but the values keep
> going.
>
> Then
>
> Double dbl = Double.longBitsToDouble( val );

 
Reply With Quote
 
Gido
Guest
Posts: n/a
 
      07-06-2003
Roedy

Your web site is a gold mine! Thanks so much for your generous contributions.

Thanks
Gido


Roedy Green <> wrote in message news:<>. ..
> On 5 Jul 2003 11:03:55 -0700, (Gido) wrote or
> quoted :
>
> >I am trying to read values from a binary file in the WINDOWS platform.

>
> see http://mindprod.com/jgloss/endian.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
little endian , big endian , big headache manishster@gmail.com C Programming 5 08-31-2006 12:28 AM
Little Endian to Big Endian invincible C++ 9 06-14-2005 10:21 PM
Little Endian to Big Endian for 32 bit invincible C++ 1 06-14-2005 04:20 PM
float: IEEE, big endian, little endian Ernst Murnleitner C++ 0 01-13-2004 01:48 PM
convert from BIG-ENDIAN to LITTLE-ENDIAN hicham C++ 2 07-02-2003 04:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57