Convert 2 bytes to decimal with special table

I have a 2 byte array (21, 121) that needs to be converted to a decimal value. The machine on which I read the numbers includes this handy little table in the manual:

High low conversion

The problem is that I'm not sure what this handy little table is trying to tell me. Can someone help interpret it and suggest a way I can convert it to decimal using C #?

I usually used BitConverterto convert it, but in this case I get the value 30977. Since this is a temperature value, I find it hard to believe that it is hot ... so I suspect my regular use of BitConvert is not enough.

+4
source share
4

, :

public static float GetTemperature(byte[] data, int start = 0)
{
    return (sbyte)data[start] + data[start + 1] / 256.0f;
}

EDIT: .

EDIT: , , . - , - . , , . Sidenote: , , . , , , . , , 256 (2 ** 8).

BitConverter , .

:

public static short GetShort(byte[] data, int start)
{
    return (short)(data[start] * 256 + data[start + 1]);
}

public static float GetTemperature(byte[] data, int start)
{
    return GetShort(data, start) / 256.0f;
}
+5

, 0,0039 ( ) 0,5 ( ). 1, . - 128, . , .

, 8 .

+1

21.472 C , (21) "char" -127 = > 127. (2 ^ 6 + 2 ^ 5 +...) , 2 ^ 7 - . ,

21 = 21

149 = - 21

149 = 128 (0x80) + 21

- , , 256 (2 ^ 8) So 121/256 = 21.472

+1

, , . , , "" "1", 1/256 2^-8, . 16- , "" , -2^7 2^7.

, 7 - "16- " 2 ^ 7; 4 2 ^ 4 "13- ", .. 1/256 * 2 ^ 12.

?

( , byte_high (signed) + byte_low ( )/256f , !)

PS: This makes your (21,121) at 21 + 121/256, approximately 21.47, which, apparently, is the allowable room temperature in Celsius.

+1
source

All Articles