Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

16-bit MCU and DSC Programmer’s Reference Manual
DS70157F-page 82 © 2005-2011 Microchip Technology Inc.
4.11.2 Integer and Fractional Data Representation
Having a working knowledge of how integer and fractional data are represented on the
dsPIC30F, dsPIC33F, and dsPIC33E is fundamental to working with the device. Both integer and
fractional data treat the Most Significant bit as a sign bit, and the binary exponent decreases by
one as the bit position advances toward the Least Significant bit. The binary exponent for an N-bit
integer starts at (N-1) for the Most Significant bit, and ends at ‘0’ for the Least Significant bit. For
an N-bit fraction, the binary exponent starts at 0for the Most Significant bit, and ends at (1-N)
for the Least Significant bit (as shown in
Figure 4-12 for a positive value and in Figure 4-13 for a
negative value).
Conversion between integer and fractional representations can be performed using simple
division and multiplication. To go from an N-bit integer to a fraction, divide the integer value by
2
N-1
. Similarly, to convert an N-bit fraction to an integer, multiply the fractional value by 2
N-1
.
Figure 4-12: Different Representations of 0x4001
Figure 4-13: Different Representations of 0xC002
Integer:
1.15 Fractional:
0x4001 = 2
14
+ 2
0
= 16384 + 1 = 16385
0x4001 = 2
-1
+ 2
-15
= 0.5 + .000030518 = 0.500030518
Implied Radix Point
0 1 0 0 0000 00 0 00 0 0 1
10 0 0 0000 00 0 00 0 0 1
-2
15
2
14
2
13
2
12
. . . . . .
2
0
2
-15
-2
0
. 2
-1
2
-2
2
-3
. . . . . .
Integer:
1.15 Fractional:
0xC002 = -2
15
+ 2
14
+ 2
1
= -32768 + 16384 + 2 = -16382
0xC002 = -2
0
+ 2
-1
+ 2
-14
= -1.0 + 0.5 + 0.000061035 = -0.499938965
Implied Radix Point
1 1 0 0 0000 10 0 00 0 0 0
11 0 0 0000 10 0 00 0 0 0
-2
15
2
14
2
13
2
12
. . . . . .
2
0
2
-15
-2
0
. 2
-1
2
-2
2
-3
. . . . . .
1 1 0 0 0000 10 0 00 0 0 0

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh