On Wed, 3 Feb 1999, Carlo E. Prelz wroteSee added comments to code:

>       Subject: Re: little endian & big endian
>       Date: Tue, Feb 02, 1999 at 06:00:22PM -0800
> 
> Quoting [EMAIL PROTECTED] ([EMAIL PROTECTED]):
> 
> > > I now have two different opinions. Some say Java is big-endian, some
> > > say it depends which machine it's on. Who's right? Proofs, please.
> > 
> > Class files and serialized objects are MSB.  The endianness of the VM
> > itself is implementation dependent; however, if you could devise a
> > pure-Java program that could detect the endianness of the VM, you
> > would have found a bug in the spec.
> 
> 
> Just wondering... I wrote the following short class:
> 
> --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
> 
> public class Test_endian
> {
>   static public void main(String[] args)
>   {
>     short s=0xa0b;
>     int b1=(int)(s>>8);
>     int b2=(int)(s&0xf);
> 
>     System.out.println("First byte: "+Integer.toString(b1,16));
>     System.out.println("Second byte: "+Integer.toString(b2,16));
>   }
> }
> 
> --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
> 
> This is my output, on a vanilla intel linux machine:
> 
> --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
> 
> Wed Feb  3 07:45:55  eccolo:~/test <^_^> java Test_endian
> First byte: a
> Second byte: b
> Wed Feb  3 07:46:22  eccolo:~/test <^_^>

This is exactly what I'd expect on a big-endian machine (where I'm much
more practiced and comfortable). On a little-endian machine, the integer
0a0d is stored as bytes 0x0b, 0x0a.

To see what the hardware is really doing, yu have to be able to redefine
storage. You can do this in fortran, cobol, PL/1, C and C++. However, not in
java.


-- 
Cheers
John Summerfield
http://os2.ami.com.au/os2/ for OS/2 support.
Configuration, networking, combined IBM ftpsites index.

Reply via email to