Could some Java guru please provide some feedback ? I am provided with
an array of bytes - coming from a physical device and I want to
convert them to integers. To do this, I am taking 4 bytes at a time
and converting these to integers. Is that correct ?
Secondly, is sign preserved in this operation? The input is a time
dependent sinusoidal signal - that is, the bytes will have sign
information encoded in them. I am curious to know if this sign
information will be available once I convert the bytes to integers.
Any suggestions or hints would be extremely helpful. Thanks in advance
for your help.
Roedy Green - 21 Mar 2008 02:01 GMT
On Thu, 20 Mar 2008 17:28:42 -0700 (PDT), "cpptutor2000@yahoo.com"
<cpptutor2000@yahoo.com> wrote, quoted or indirectly quoted someone
who said :
>To do this, I am taking 4 bytes at a time
>and converting these to integers. Is that correct ?
are they little or big endian?
see http://mindprod.com/jgloss/endian.html
you can read them as a stream with DataInputStream or
LEDataInputStream.
See http://mindprod.com/products1.html#LEDATASTREAM

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lothar Kimmeringer - 21 Mar 2008 12:30 GMT
> Could some Java guru please provide some feedback ? I am provided with
> an array of bytes - coming from a physical device and I want to
> convert them to integers. To do this, I am taking 4 bytes at a time
> and converting these to integers. Is that correct ?
Depends on the device sending the data. Older devices define
an integer as 16 bit wide or (the more older ones) only 8 bits.
So in that case you need to take two bytes or only one. Also
you have to check if the data is coming encoded in little or
big endian and how the bit-order is (e.g. with ISDN you need
to read the bits backwards).
So without concrete knowledge of the device in question, nobody
can give you a final answer.
Regards, Lothar

Signature
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!