Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7649869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:04:49+00:00 2026-05-31T11:04:49+00:00

So this sensor I have returns a signed value between -500-500 by returning two

  • 0

So this sensor I have returns a signed value between -500-500 by returning two (high and low) signed bytes. How can I use these to figure out what the actual value is? I know I need to do 2’s complement, but I’m not sure how. This is what I have now –

real_velocity = temp.values[0];
    if(temp.values[1] != -1)
        real_velocity += temp.values[1];

    //if high byte > 1, negative number - take 2's compliment
    if(temp.values[1] > 1) {
        real_velocity = ~real_velocity;
        real_velocity += 1;
    }

But it just returns the negative value of what would be a positive. So for instance, -200 returns bytes 255 (high) and 56(low). Added these are 311. But when I run the above code it tells me -311. Thank you for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:04:51+00:00Added an answer on May 31, 2026 at 11:04 am
     -200 in hex is 0xFF38, 
    

    you’re getting two bytes 0xFF and 0x38,
    converting these back to decimal you might recognise them

    0xFF = 255,
    0x38 = 56
    

    your sensor is not returning 2 signed bytes but a simply the high and low byte of a signed 16 bit number.

    so your result is

    value = (highbyte << 8) + lowbyte
    

    value being a 16 bit signed variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Sensor.TYPE_LINEAR_ACCELERATION. Accrording to documentation, starting since level 9 (gingerbread) this
I have a closed-source API for some hardware sensor that I use to query
This is a bit of a long shot, but if anyone can figure it
I am working on a 3D model reconstruction application with Kinect sensor. I use
I'm having a tough time with this one, I have a class which populates
I have a sensor which uses RS422 to spit out messages over serial. (I
I have some tables in a MySQL database to represent records from a sensor.
I have a device driver that uses the following algorithm to convert a value
General I have two kind of users, and one field (cluster) that I want
So I have a little sensor in my 'scene' and when it gets blocked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.