Reading an Excel file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthias Drescher

    #1

    Reading an Excel file

    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),

    Bit |Mask |Contents
    ----------------------------------------------------------------------------
    ----------------------
    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($intv al);

    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


Working...