Please provide some feedback - convert byte array to integer

C

cpptutor2000

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.
 
L

Lothar Kimmeringer

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
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top