Bernd Kreimeier writes:
> The only statement I found is in the VMspecs, basically
> saying:
>
> Multibyte data items are always stored in big-endian
> order, where the high bytes come first.
>
> Does this apply to "int" in memory? Is the VM on Linux
> using big endian and swaps when it interfaces native code?
> Is a local int variable in a method stored as big endian?
Not having seen the source, I can't give a specific answer. There is
no way you can tell what the VM "really" uses. From the Java side,
the VM is big-endian (per your quote from the spec above). From the
JNI side, the VM has the endianness of the native hardware (per the
JNI spec). There is no other interface to the VM, so I'm not sure why
it would matter what the VM "really" uses.
> Let's say I want to hand over 4 bytes as a single int,
> to native code that requires a given order, e.g.
> OpenGL C4UB, MSB==Red
> e.g. as an int[] array.
>
> Is there a pure Java way to put together the 32bpp ints
> from the 4 bytes that works for Linux and Solaris?
I am not sure what you mean here. Do you have a native method that
wants an int[], and each element of the array contains four 8-bit
fields, with the MSB being red? That's easy. In Java, set the MSB of
your int to the red field. Then the MSB of the int elements returned
by JNI will be the red value, on all platforms. JNI performs endian
conversion, if necessary, automatically. That's the major benefit of
JNI.
If you have a native method that wants a byte[], and it gloms together
four contiguous elements and treats them as an integer according to
the processor's hardware endianness, then your native interface is
irreparably screwed up, and you should fix the interface instead of
trying to program around it.
> Is there a pure Java way to determine the endianess of
> the hosting system hardware?
>
> What I am looking for is essentially
> java.lang.Integer.byteBitsToInt( byte[] ).
No, there is no such thing. Search the archives for the last batch of
postings on endianness, or email me privately and I'll resend some
earlier mails.
Best,
daniel dulitz
Valley Technologies, Inc. Peak Performance Real-Time DSP
State College, PA
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]