Difference between revisions of "Two's complement"

From OpenMotics
Jump to navigation Jump to search
(Created page with "Values like offset are being written in Two's complement notation. This means that, when using Basic Action, a byte value (0-255) can also represent a negative value. Byte va...")
 
 
(3 intermediate revisions by the same user not shown)
Line 51: Line 51:
 
|align="center"|+127
 
|align="center"|+127
 
|}
 
|}
 +
 +
Example:
 +
We want to program an offset of -2,5°C for sensor2 so the actual measured temperature will be displayed as follows: Display value sensor2=measured value(in °C) + (- 2,5°C). If we want to convert this to a Basic Action, we know that system values work in 0.5°C so we need to program -5. Following CLI instruction will program an offset -2,5°C for sensor 2:
 +
::<code>basic action activate 7 2 0 251 0 0</code>
 +
With following instruction, you can check if the result is correct:
 +
::<code>sensor list</code>

Latest revision as of 13:37, 25 October 2020

Values like offset are being written in Two's complement notation. This means that, when using Basic Action, a byte value (0-255) can also represent a negative value.

Byte value is converted in Two's complement:

Byte Value Two's complement
128 -128
... ...
251 -5
252 -4
253 -3
254 -2
255 -1
0 0
1 +1
2 +2
3 +3
4 +4
5 +5
... ...
127 +127

Example: We want to program an offset of -2,5°C for sensor2 so the actual measured temperature will be displayed as follows: Display value sensor2=measured value(in °C) + (- 2,5°C). If we want to convert this to a Basic Action, we know that system values work in 0.5°C so we need to program -5. Following CLI instruction will program an offset -2,5°C for sensor 2:

basic action activate 7 2 0 251 0 0

With following instruction, you can check if the result is correct:

sensor list