Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

little endian/big endian problem

Posted on 1997-08-05
4
Medium Priority
?
1,296 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 ?
0
Comment
Question by:byang
  • 2
4 Comments
 
LVL 3

Author Comment

by:byang
ID: 1224544
Edited text of question
0
 
LVL 1

Expert Comment

by:bogamo
ID: 1224545
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)
0
 
LVL 3

Author Comment

by:byang
ID: 1224546
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.
0
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 100 total points
ID: 1224547
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question