Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding together the LSB and MSB to obtain a value

Tags:

c#

byte

bit

I am reading data back from an imaging camera system, this camera detects age, gender etc, one of the values that comes back is the confidence value, this is 2 bytes, and is shown as the LSB and MSB, I have just tried converting these to integers and adding them together, but I don't get the value expected.

is this the correct way to get a value using the LSB and MSB, I have not used this before.

Thanks

like image 848
Racing57 Avatar asked Oct 23 '25 17:10

Racing57


1 Answers

Your value is going to be:

Value = LSB + (MSB << 8);

Explanation:

A byte can only store 0 - 255 different values, whereas an int (for this example) is 16 bits.

The MSB is the left hand^ side of the 16 bits, and as such needs to be shifted to the left side to change the bits used. You can then add the two values.

I would suggest looking up the shifting operators.

^ based on endienness (Intel/Motorola)

like image 106
Sarima Avatar answered Oct 26 '25 06:10

Sarima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!