Each byte of the mantissa normally represents two decimal digits. For positive numbers an offset of 1 is added to avoid null bytes, while for negative numbers an offset of 101 is added to the negated digit pair. Thus a mantissa byte with the decimal value of 100 might represent the digit pair "99" in a positive number, or the digit pair "01" in a negative number. The interpretation must be based on the sign bit. Negative numbers with less than 20 mantissa bytes also have a byte with the (impossible) decimal value 102 appended. I don't know what purpose this serves.
If there are an odd number of significant digits before the decimal point, the first mantissa byte can only represent 1 digit because the decimal exponent must be even. In this case, the 20byte mantissa can represent at most 39 decimal digits. However, the last digit may not be accurate if a more precise value has been truncated for storage. This is why the maximum guaranteed precision for Oracle numbers is 38 decimal digits, even though 40 digits can be represented.
The decimal exponent is guaranteed to be even by the alignment of the mantissa. Thus the value stored for the exponent is always halved and is expressed such that the decimal point falls before the first digit of the mantissa. It again represents a pair of decimal digits, this time with an offset of 64 for positive numbers, and 63 for the negated exponent of negative numbers. Thus a set of exponent bits with the decimal value of 65 might represent the exponent +2 in a positive number, or the exponent 4 in a negative number. Please note that the encoding of the exponent is based on the sign of the number, and not on the sign of the exponent itself.
Finally, there are special encodings for zero, and positive and negative infinity.
Zero is represented by the single byte 0x80.
Negative infinity is represented by 0x00, and positive infinity is represented by the two bytes 0xFF65.
These are illustrated in the listing below.
For the rest, the best way to familiarize yourself further with the internal representation of numbers is to use the dump function to examine the representation of some sample values. This is simulated below. Just type a number and then press "Enter" to check out its representation. For example, try to find out why 110 takes one more byte of storage than 1100 despite being a smaller number.
SQL> select n, dump(n,16) from special_numbers; N DUMP(N,16)   0 Typ=2 Len=1: 80 ~ Typ=2 Len=1: 0 ~ Typ=2 Len=2: ff,65
[an error occurred while processing this directive]
© Ixora Pty Ltd. All rights reserved.
12Oct2007 22:22 
