Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

sparc/intel endian

Thread view: 
palmis - 22 Dec 2005 11:58 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.
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.