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.
Roedy Green - 22 Dec 2005 12:35 GMT
>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

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
palmis - 22 Dec 2005 13:33 GMT
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?
Dave Glasser - 22 Dec 2005 13:58 GMT
"palmis" <francesca.palmisano4@tin.it> wrote on 22 Dec 2005 05:33:01
-0800 in comp.lang.java.programmer:
>Some message field are int(4 byte), short(2 byte)....
>So I have to reverse order byte.
[quoted text clipped - 3 lines]
>
>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.

Signature
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
palmis - 22 Dec 2005 14:44 GMT
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.
Dave Glasser - 22 Dec 2005 20:59 GMT
"palmis" <francesca.palmisano4@tin.it> wrote on 22 Dec 2005 06:44:09
-0800 in comp.lang.java.programmer:
>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.
Whatever. Let us know how that works out. :)

Signature
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
Roedy Green - 22 Dec 2005 14:53 GMT
>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.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Dave Glasser - 22 Dec 2005 13:49 GMT
"palmis" <francesca.palmisano4@tin.it> wrote on 22 Dec 2005 03:58:37
-0800 in comp.lang.java.programmer:
>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.)

Signature
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
Alun Harford - 24 Dec 2005 02:52 GMT
> 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