Racing57
Racing57

Reputation: 91

adding together the LSB and MSB to obtain a value

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

Upvotes: 3

Views: 18073

Answers (2)

Ceisc
Ceisc

Reputation: 1308

Assuming that MSB and LSB are most/least significant byte (rather than bit or any other expansion of that acronym), the value can be obtained by MSB * 256 + LSB.

Upvotes: 1

Sarima
Sarima

Reputation: 749

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)

Upvotes: 7

Related Questions