Campbell Scientific CR23X Micrologger User Manual
Page 271

APPENDIX C. BINARY TELECOMMUNICATIONS
C-3
The Flags byte expresses datalogger user flag
status. The most significant bit represents Flag
8, and so on to the least significant bit which
represents Flag 1. If a bit is set, the user flag is
set in the datalogger.
The optional ports byte (currently on return if
requested by a CR23X J command) expresses
the datalogger port status. The most significant
bit represents Port 8, and so on to the least
significant bit which represents Port 1.
For each input location requested by the J
command, four bytes of data are returned. The
bytes are coded in Campbell Scientific, Inc.
Floating Point Format. The format is decoded
to the following:
Sign(Mantissa*2
(Exponent)
)
Data byte 1 contains the Sign and the
Exponent. The most significant bit represents
the Sign; if zero, the Sign is positive, if one, the
Sign is negative. The signed exponent is
obtained by subtracting 40 HEX (or 64 decimal)
from the 7 remaining least significant bits.
Data bytes 2 to 4 are a binary representation of
the mantissa with byte 2 the most significant and
4 the least. The mantissa ranges in value from
80 00 00 hex (0.5 decimal) to FF FF FF HEX
(1-2
-24
decimal). The one exception is for zero
which is 00 00 00 00 HEX.
The Mantissa is calculated by converting Data
bytes 2 to 4 into binary. Each bit represents
some fractional value which is summed for all
24 bits. The bits are arranged from MSB to
LSB with the most significant as bit
23
and least
significant as bit
0
. The value that each bit
represents = 2
n-24
; where n=bit location. For
example, if there was a 1 at bit
20
, it’s value
would be 2
(20-24)
or 2
-4
.
A simple method for programming this is as
follows:
Set Mantissa = 0.
Set Bit Value = 0.5.
For loop count = 1 to 24 do the following:
If the MSB is one, then add Bit Value to the
Mantissa.
Shift the 24 bit binary value obtained from
Data bytes 2 to 4 one bit to the left.
Multiply Bit Value by 0.5.
End of loop.
Another method that can be used as an
estimate is to convert Data bytes 2 to 4 from a
long integer to floating point and dividing this
value by 16777216.
As an example of a negative value, the
datalogger returns BF 82 0C 49 HEX.
Data byte 1 = BF HEX.
Data byte 2 to 4 = 82 0C 49 HEX (or 8522825
decimal).
Data byte 1 is converted to binary to find the
Sign. BF HEX = 10111111 BINARY.
The most significant bit is 1 so the Sign is
NEGATIVE.
The exponent is found by subtracting 40 HEX
from the remaining least significant bits.
Converting the binary to hexadecimal, 111111
BINARY = 3F HEX (or 63 decimal).
3F - 40 HEX = FF FF FF FF FF HEX. Or in
decimal: 63 - 64 = -1.
Exponent is -1 decimal.
The binary representation of Data bytes 2 to 4
is: 10000010 00001100 01001001.
Summing all the fractional values: 2
-1
+ 2
-7
+
2
-13
+ 2
-14
+ 2
-18
+ 2
-21
+ 2
-24
= 0.50800.
Using the estimate method to find the Mantissa =
82 0C 49 HEX / 1 00 00 00 HEX (or 8522825 /
16777216) which is 0.50800 decimal.
The value is then (-)0.508*2
-1
which equals
-0.254.