470,849 Members | 1,293 Online

Hi there,

I have a litte problem while reading from a Excelfile.
Im try to read a 4 byte value and convert it into an integer or floating
point value with the following criteria:

Thats what the definiton says:

An RK valie is an encoded integer or floating-point value. RK values have a
size of 4 bytes and are used to decrease the size for floating-point values.
Structure of an RK value (32-bit value),

----------------------------------------------------------------------------
----------------------
0 00000001(hex) 0 = Value not changed 1 = Value is
multiplied by 100
1 00000002(hex) 0 = Floating Point Value 1 = Signed
integer value
31-2 FFFFFFFC(hex) Encoded Value

If Bit 1 is cleared, the encoded value represents the 30 most significant
bits of an IEEE 754 floating point value (64-bit double precision). The 43
least significant bits must be set to zero. If bit 1 is set, the encoded
value represents a signed 30-bit integer value. To get the correct integer,
the encoded value has to be shifted right arithmetically by 2 bits. If bit 0
us set, the decoded value (both integer and floating-point) must be be
divided by 100 to get the final result.

So far what the definition says.

Could anybody helpme with a function that does what the definiton says ???

I tried to solve this with the following function:

<?
function double4byte()
{
// for testing a fixed value:
// test float value 1
//\$val = 0x3FF00000;
// test float value 2
//\$val = 0x3FF00001;
// test integer value 1
//\$val = 0x004B5646;
// test integer value 2
\$val = 0x004B5647;

if ((\$val & 0x02) != 0)
{
echo "Integer ... ";
\$intval = \$val >> 2;
\$value = doubleval(\$intval);

if ((\$val & 0x01) != 0)
{
echo "multiplied by 100 ... ";
\$value /= 100;
}
return \$value;
}
else
{
echo "floating point ... ";
\$valbits = \$val & 0xfffffffc;
\$valbits = \$valbits << 32;
\$value = \$valbits;

if ((\$val & 0x01) != 0)
{
echo "multiplied by 100 ... ";
\$value /= 100;
}
return \$value;
}
}

echo double4byte();

?>

I´m quite sure that it works for the integer values, but the floating point
operations are a big problem for me.
Could anybody help me please ???

Best regards Matthias
Jul 17 '05 #1
0 1479 ### This discussion thread is closed

Replies have been disabled for this discussion.

### Similar topics

 reply views Thread by David Alliet | last post: by 1 post views Thread by mail2atulmehta | last post: by 1 post views Thread by Turner, GS \(Geoff\) | last post: by 4 posts views Thread by Phoebe. | last post: by 5 posts views Thread by Scott M. Lyon | last post: by 9 posts views Thread by dba123 | last post: by 3 posts views Thread by Brad | last post: by 3 posts views Thread by Bharathi | last post: by 1 post views Thread by sachinkale123 | last post: by 1 post views Thread by ndedhia1 | last post: by reply views Thread by ryjfgjl | last post: by reply views Thread by prepawan | last post: by reply views Thread by tracyyun | last post: by 1 post views Thread by MarkDoronin | last post: by reply views Thread by sjain6 | last post: by reply views Thread by milkinvl | last post: by reply views Thread by gglobus | last post: by reply views Thread by Ravipg | last post: by reply views Thread by zachatmarco | last post: by