Solved

little endian/big endian problem

Posted on 1997-08-05
4
1,281 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 43
groovy example issue 10 90
micro services spring boot application error 3 148
Java Loop 6 49
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now