Floating Point Example - Storing an integer
A floating-point number consists of at least 3 bytes of 1's and 0's. The information stored in these bytes includes the sign, exponent, and mantissa of the number. Up to five additional bytes may be used to store the mantissa. SAS, by default, stores numbers in eight bytes.
_ _ _ _ _ _ _ _ |
_ _ _ _ _ _ _ _ |
_ _ _ _ _ _ _ _ |
byte 1 |
byte 2 |
byte 3 |
Numbers are represented in base-2 exponential notation. For example, 13_{10} (read thirteen, base 10) is represented in base-2 as 1101 = 1.101 × 10^{11}. [The base-10 equivalent of "10^{11}" is 2^{3}.] Here the sign is positive, the exponent is 11_{2}, and the mantissa is 1.101.
The sign of a floating-point number is indicated by the leading bit of the first byte: 0=positive, 1=negative. For the example above, the number is positive.
0 _ _ _ _ _ _ _ |
_ _ _ _ _ _ _ _ |
_ _ _ _ _ _ _ _ |
byte 1 |
byte 2 |
byte 3 |
The remaining 7 bits of the first byte and the first 4 bits of the second byte are for the exponent. In order to allow for negative exponents, a bias is added to the true exponent before it is stored. The bias is 1023_{10} or 1111111111_{2}. For the example above, the exponent is 11_{2}. Adding the bias, the stored value is 10000000010_{2}.
0 1 0 0 0 0 0 0 |
0 0 1 0 _ _ _ _ |
_ _ _ _ _ _ _ _ |
byte 1 |
byte 2 |
byte 3 |
The mantissa will always have a leading one to the left of the decimal. The leading one and the decimal are not stored. In the example above, the mantissa is 1.101_{2}. Thus the stored value is 101. Any remaining bits are padded with zeroes.
0 1 0 0 0 0 0 0 |
0 0 1 0 1 0 1 0 |
0 0 0 0 0 0 0 0 |
byte 1 |
byte 2 |
byte 3 |
Usually the floating-point number is written in hexadecimal form (base-16). Each group of four bits above may be represented with a single hexadecimal number. For the example, the floating-point number is 402A00_{16}.