Results 1 to 3 of 3
  1. #1
    Krooger is offline Member
    Join Date
    Nov 2008
    Rep Power

    Question How do I convert Little endian to Big endian?


    I am reading a file a byte at a time and storing it in a Byte array.
    There is one point in the file where I suspect the bytes are being stored in little endian format.
    Since java uses only Big endian (right?) how would I go about taking this Byte, extracting its little endian value doing what ever I need to do to it and then store it back as a little endian format byte?

    Thank you for any help.


    00000010 - if i take the value in java it will be 2 i need to have java take its value as 64, then I would lets say half this value making it 32 and then store it back in little endian format so it would store as 00000100.
    A built in function would be great but I havent had any luck finding any...

  2. #2
    Kenan89 is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default .

    i found this on google maybe you can use it:

    Java Code:
    // 2-byte number
    int SHORT_little_endian_TO_big_endian(int i)
        return ((i>>8)&0xff)+((i << 8)&0xff00);
    // 4-byte number
    int INT_little_endian_TO_big_endian(int i)

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Read the API documentation for the ByteBuffer class; you can create one given an array of bytes and you can set the byte order with one of its order( ... ) methods; at the end just read integer values from the buffer.

    kind regards,


Similar Threads

  1. Anyone know .wav data points endian format?
    By Krooger in forum New To Java
    Replies: 1
    Last Post: 12-24-2010, 10:40 AM
  2. convert XML using XSL
    By rajjan4u in forum XML
    Replies: 3
    Last Post: 11-20-2009, 05:37 PM
  3. Convert to Int
    By 6kyAngel in forum New To Java
    Replies: 0
    Last Post: 03-06-2009, 10:18 AM
  4. how to convert xml to xsd
    By adi in forum XML
    Replies: 2
    Last Post: 02-12-2009, 03:43 PM
  5. Replies: 3
    Last Post: 01-15-2008, 08:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts