
Appendix
PROFIBUS manual
Version FELD-V2002.02
Page 39
Calculation tip
This calculation can be performed relatively easily by bit manipulation
directly at the binary level using the following sequence of operations:
First, as described above, the three components of sign bit, exponent and
mantissa must be obtained from the four bytes by copying and masking bits.
Example:
As described above, the bytes 0x3F,0x40,0x00,0x00
become
sign=0, exponent=0x7E(126dec), mantissa =100 0000 0000 0000 0000 0000b
or (0x400000)
Calculating the exponent value
by subtracting 0x7F (127dec) from the contents of the exponent field
Example:
Contents_ExponentField – 127dec = Exponent value
126dec – 127dec = -1
Adding the 1.0 i.e. inserting a 1 and a decimal point in front of the mantissa
Example
:
Mantissa was 100 0000 0000 0000 0000 0000b
new mantissa is 1.100 0000 0000 0000 0000 0000b
Taking into account the exponent.
A negative exponent shifts the decimal point to the left, a positive exponent to
the right. Thus, if an exponent of -3 was calculated, the decimal point is
shifted three places to the left; for an exponent of +1 the decimal point moves
one place to the right.
Example:
Mantissa was: 1.100 0000 0000 0000 0000 0000b
Exponent was: -1
new mantissa with exponent is: 0.1100 0000 0000 0000 0000 0000b
Calculating the integer positions
The integer positions (places in front of the decimal point) are interpreted in a
similar way to above as positive powers of two which are added together:
Example:
integer position of: 0.1100 0000 0000 0000 0000 0000b
is
0b
0*2
0
+ [0*2
1
+0*2
2
+0*2
3
...] = 0
Calculating the decimal positions
Like the integer positions, the decimal positions also represent powers of two,
but in this case negative powers.
example
: decimal position of:
: 0.1100 0000 0000 0000 0000 0000b
is 1100 0000 0000 0000 0000 0000b
1*2
-1
+ 1*2
-2
+ 0*2
-3
+ [0*2
-4
+ 0*2
-5
+ .. =1*0.5 + 1*0.25 + 0*0.125 [...] =
0.75