# Understanding LSB and MSB

In reference to one interface control document, I found difficulty in understanding this concept. There is one parameter having LSB of 0.0625 and MSB of 2048 that should be transmitted from one piece of equipment to another. It's range is 0 to 2400.

This should be transmitted using only one word. That is 2 bytes.

Now the problem is: I understood this as that parameter is being measured by one measurement system with a resolution of 0.0625. Since it is decimal number how can we transmit this continuous range parameter using 2 bytes which are purely integers (unsigned range for 2 bytes is 0 to 65535)?

That parameter is speed, which is being measured by an INS-GPS avionics system and is being transmitted to the CPU using only 2 bytes.

How should I understand this?

How can we represent a continuous decimal parameter as a discrete integer parameter?

• What? Can you try to rewrite this so it's understandable? – whatsisname Jan 26 '18 at 17:40
• Downvoters, please note there’s plenty of context here if you’ve seen Fixed Point Numbers in embeddes dev before. – RubberDuck Jan 26 '18 at 23:05
• Note: being personally unfamiliar with this domain is not a good reason to downvote or vote to close this question as "unclear what you're asking." – Karl Bielefeldt Jan 27 '18 at 17:20
• @KarlBielefeldt: The problem is not the domain, it's the way the OP is interpreting the domain. – Robert Harvey Jan 27 '18 at 17:35
• @Ãjay: Technically, your range isn't continuous; it's discontinuous with a resolution of 0.0625. – Robert Harvey Jan 27 '18 at 17:41

TL;DR:

The following function will do the conversion from physical value to 16-bit code:

short valueToCode(double value) {
return round(16.0 * value);
}


Long explanation

An unsigned 16-bit value has 16 bits (of course), the leftmost one called the MSB (most significant bit), and the rightmost is the LSB (least significant bit).

Read as normal integers, a 1-bit in the LSB position accounts for a value 1, and a 1-bit in MSB position gives 32768.

In your case, the 16-bit number is meant to represent numbers with fractional part, one LSB standing for 0.0625 (= 1/16), and the MSB for 2048 (= 32768/16). That's consistent, meaning that you always get the fractional number by dividing the 16-bit code by 16. Or, if you want to find the code that most closely matches some desired fractional value, multiply that by 16, and take the closest integer.

Some examples (giving the value you want to achieve, the code that most closely gives that value, and the effective value):

Desired       Code (dec + bin)          Resulting Value
0.0625      1 = 0000000000000001       0.0625  (the LSB case)
0.1         2 = 0000000000000010       0.125
1.0        16 = 0000000000010000       1.0
20.5       328 = 0000000101001000      20.5
2048.0     32768 = 1000000000000000    2048.0    (the MSB case)

• I don't understand your second example. Why is "desired" truncated? – Robert Harvey Jan 27 '18 at 17:39
• Shouldn't 20.5 be 328 in the Code column? You've got the 1/16th bit set, but you shouldn't need to. It should be 0x148 or 0b0000 0001 0100 1000. – user1118321 Jan 27 '18 at 22:15
• @user1118321: You're right. I'll correct the numbers. – Ralf Kleberhoff Jan 28 '18 at 9:53
• @RobertHarvey I added a better table explanation. "Desired" means the value I want to produce, even if the fixed-point representation only allows for some approximation. – Ralf Kleberhoff Jan 28 '18 at 9:58

That’s poorly written documentation. They’re assuming that you know they’re using a Fixed Point number format.

LSB 0.0625 and MSB 2048

This would have been more easily understood if it was written as powers of 2.

0.0625 == 2-4

2048 == 211

So, you end up with a fixed point number in the following format.

MSB —> LSB

| 211 | 210 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | . | 2-1 | 2-2 | 2-3 | 2-4 |

Or

000000000000.0000


For detailed information see this Introduction to Fixed Point Number Format