Solved

little endian/big endian problem

Posted on 1997-08-05
4
1,292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

636 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