Previous PageNext Page

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, 1310 (read thirteen, base 10) is represented in base-2 as 1101 = 1.101 × 1011. [The base-10 equivalent of "1011" is 23.] Here the sign is positive, the exponent is 112, 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 102310 or 11111111112. For the example above, the exponent is 112. Adding the bias, the stored value is 100000000102.

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.1012. 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 402A0016.

Previous PageTable Of ContentsNext Page