We help IT Professionals succeed at work.

little endian/big endian problem

byang
byang asked
on
Medium Priority
1,318 Views
Last Modified: 2010-05-18
How can I tell if the host is little endian or big endian ? Also, does Java have byte-swap, ntoh(), and hton() functions ?
Comment
Watch Question

Author

Commented:
Edited text of question

Commented:
You shouldn't have to worry about endianness...  Java is the same across all platforms..

When using java to talk to non-java however, I just use my friends >>, <<, and &. (bitwise and and shift)

Author

Commented:
I have to parse a binary file, so I really need to worry about it. It's for the same reason you call ntoh() and hton() when doing socket programming.
Try using a DataOutputStream to write out an int of value 1.
Attach a DataInputStream to the other end and read the four
bytes off as four bytes.  The first byte will be 1 on some
platforms, and the fourth will be 1 on the others.

I don't think Java has any byte-swapping functions.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.