Results 1 to 2 of 2
  1. #1
    TorErik86 is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default Reading a two's complement number from a InputStream

    Hello,

    First, I am new to this forum, so sorry if I have posted this thread in a wrong place.

    Now to my problem.

    I have an application that is receiving data from an accelerometer. As we know, accelerometer data can be positive or negative, depending on which way we are moving along a given axis. So, my problem is this:

    On the accelerometer, negative data is sent using two's complement binary notation, but when I receive it in my application, using int data = InputStream.read(), this number is stored as a normal int. So instead of getting values between -128 and 127 I get values between 0 and 255.

    So what I want is to simply read from the InputStream and get a 8 bit binary value, instead of an int. Can anyone help me with my problem?

    Best regards,
    Tor-Erik

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default

    what I want is to simply read from the InputStream and get a 8 bit binary value, instead of an int.
    The int returned by read can be cast to a byte.

Similar Threads

  1. Reading inputstream on socket
    By javanetworknew in forum Networking
    Replies: 1
    Last Post: 04-27-2010, 11:01 AM
  2. Reading or changing sequenc number in TCP packets
    By islamfunny in forum Networking
    Replies: 4
    Last Post: 09-23-2008, 01:44 PM
  3. Replies: 0
    Last Post: 11-27-2007, 10:23 AM
  4. Reading bytes from InputStream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-25-2007, 07:51 PM
  5. Un expected behaviour when reading from inputstream
    By adoorsarath in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2007, 05:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •