Formats for NUMERIC and DECIMAL data types vary as a function of precision.
struct { unsigned char sign; // sign 1 for +, 0 for - unsigned char ndig; // # digits unsigned char exp; // exponent unsigned char erracc; // should be 0 unsigned short digits[80]; };
Exponent is excess-80 form, unless the value is zero. A “zero” value is represented as:
sign = 1 ndig = 0 erracc = 0 exp = 0
lower order digit = digit[i] & 0x00FF
high order digit = digit[i] & 0xFF00
For example, consider the value 100 represented as NUMERIC(20). The binary layout of this value is:
0x0101 0x5000 0x0064 0x0000 0x0000 ...... Sign = 0x01 Number digits = 0x01 Exponent = 0x50 Erracc = 0x00 Digits = 0x0064
As another example, consider the value 32769:
0x0102 0x5000 0x0ad1 0x0003 0x0000 0x0000 .... Sign = 0x01 Number digits = 0x02 Exponent = 0x50 Erracc = 0x00 Digits = 0x0ad1 0x0003
If you translate the digits into base 10, you have:
0x0ad1 = 2769 0x0003 = 3