Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Please provide some feedback - convert byte array to integer

Thread view: 
cpptutor2000@yahoo.com - 21 Mar 2008 01:28 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 ?
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!



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.