4

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?

Kyle A
  • 164

2 Answers2

11

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)
9

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

RubberDuck
  • 9,021