Microsoft Excel uses an internal number type, called an RK number, to save memory and disk space.
Record Data
Offset |
Name |
Size |
Contents |
4 |
rw |
2 |
Row number |
6 |
col |
2 |
Column number |
8 |
ixfe |
2 |
Index to the XF record that contains the cell format |
10 |
rk |
4 |
RK number (see the following description) |
An RK number is either a 30-bit integer or the most significant 30 bits of an IEEE number. The two LSBs of the 32-bit rk field are always reserved for RK type encoding; this is why the RK numbers are 30 bits, not the full 32. See the following diagram.
There are four different RK number types, as described in the following table.
|
Encode priority |
Number (decimal) |
RK number (hex) |
Description of 30-bit |
0 |
1 |
1 |
3F F0 00 00 |
IEEE number |
1 |
3 |
1.23 |
40 5E C0 01 |
IEEE number x 100 |
2 |
2 |
12345678 |
02 F1 85 3A |
Integer |
3 |
4 |
123456.78 |
02 F1 85 3B |
Integer x 100 |
Microsoft Excel always attempts to store a number as an RK number instead of an IEEE number. There is also a specific priority of RK number encoding that the program uses. The following flowchart is a simplified version of the encoding algorithm. The algorithm always begins with an IEEE (full 64-bit) number.
You can use the following C code to demonstrate how to decode RK numbers:
double NumFromRk(long rk)
{
double num;
if(rk & 0x02)
{
// int
num = (double) (rk >> 2);
}
else
{
// hi words of IEEE num
*((long *)&num+1) = rk & 0xfffffffc;
*((long *)&num) = 0;
}
if(rk & 0x01)
// divide by 100
num /= 100;
return num;
}
main()
{
printf("%f\n", NumFromRk (0x02f1853b));
}
If you write a NUMBER record to a BIFF file, Microsoft Excel may convert the number to an RK number when it reads the file.