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 <^_^>
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
I have the same result with a simple C program doing the same
operation. Can anybody with a different-endianness machine try the
above?
Carlo
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - [EMAIL PROTECTED] che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)