sparc/intel endian

P

palmis

Hello to all,
I have my message that is a byte[ ]. I must send through
UDP from one machine intel (little endian) to one sparc (big endian).
Do you think that I must invert the order of the byte in mine byte[ ]?
thanks.
 
R

Roedy Green

I have my message that is a byte[ ]. I must send through
UDP from one machine intel (little endian) to one sparc (big endian).
Do you think that I must invert the order of the byte in mine byte[ ]?
thanks.

it depends what the bytes represent. If they a set of numbers -.255
no. If they are shorts, ints, longs, doubles etc then one end or the
other will have to do a byte sex change.

See http://mindprod.com/jgloss/endian.html
 
P

palmis

Some message field are int(4 byte), short(2 byte)....
So I have to reverse order byte.

"In JDK 1.5+ there is a method part of Integer, Long, Short and Char
called reverseBytes that will reverse the byte sex. "

I use jdk 1.3. How can I reverse my byte?
 
D

Dave Glasser

Hello to all,
I have my message that is a byte[ ]. I must send through
UDP from one machine intel (little endian) to one sparc (big endian).
Do you think that I must invert the order of the byte in mine byte[ ]?
thanks.

First, when you're dealing with byte[], I don't think byte order is a
consideration because I assume you'll be writing single bytes to the
stream, and a single byte doesn't really have a byte order.

Second, I believe Java's various OutputStreams will automatically
convert types like int to standard network byte order (big-endian)
when they're written to the stream. (Actually, in Java, they're
already big-endian regardless of the underlying hardware.)

--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net
 
D

Dave Glasser

Some message field are int(4 byte), short(2 byte)....
So I have to reverse order byte.

"In JDK 1.5+ there is a method part of Integer, Long, Short and Char
called reverseBytes that will reverse the byte sex. "

I use jdk 1.3. How can I reverse my byte?

Here again, you don't "reverse" a single byte. "Byte order" refers to
the order of bytes, not the order of bits within a single byte.


--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net
 
P

palmis

I think is correct to reverse byte order. For example if in my byte[] I
have 01 02 03, then I want 03 02 01.
 
R

Roedy Green

I use jdk 1.3. How can I reverse my byte?
look at the sample code I gave you to reverse endianness when
reading.
It is just a slight modification to take the input from a primitive
than from a binary stream. Just mask and shift to get each byte.
 
A

Alun Harford

palmis said:
Hello to all,
I have my message that is a byte[ ]. I must send through
UDP from one machine intel (little endian) to one sparc (big endian).
Do you think that I must invert the order of the byte in mine byte[ ]?
thanks.

No. It's a byte array, not an int/long/float/double. And anyway, Java is big
endian no matter what machine it happens to be running on.

Alun Harford
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top