Turn binary number 0xFFFFFFEE into a float?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JimmyR.com

    Turn binary number 0xFFFFFFEE into a float?

    I have a binary file which only has 4 bytes "FFFFFFEE". I just want to
    put it in a variable equaling 4294967278.


    How I've failed so far:

    <?

    $foo= bin2hex(file_ge t_contents('tes tplz.bin'));

    // This correctly creates the hex number but on closer inspection it
    just turned it into a string.

    $foo=intval(bin 2hex(file_get_c ontents('testpl z.bin')),16);

    // This works up until the value exceeds 2147483647, there's a
    function called floatval but it doesn't accept the ,16 argument and
    doesn't accept binary either

    settype($foo, "float");

    // Any variation of bin2hex, casting, etc don't seem to give me a
    correct answer

    echo (float)bin2hex( file_get_conten ts('testplz.bin '));

    ?>


    Please help ='/, I can't proceed with what I need to finish.
  • Anonymous

    #2
    Re: Turn binary number 0xFFFFFFEE into a float?

    "JimmyR.com " wrote:
    >
    I have a binary file which only has 4 bytes "FFFFFFEE". I just want to
    put it in a variable equaling 4294967278.
    >
    How I've failed so far:
    >
    <?
    >
    $foo= bin2hex(file_ge t_contents('tes tplz.bin'));
    >
    [...]
    // Any variation of bin2hex, casting, etc don't seem to give me a
    correct answer
    >
    echo (float)bin2hex( file_get_conten ts('testplz.bin '));
    >
    ?>
    >
    Please help ='/, I can't proceed with what I need to finish.
    $foo= hexdec(file_get _contents('test plz.bin')); should do the trick.

    Bye!

    Comment

    • JimmyR.com

      #3
      Re: Turn binary number 0xFFFFFFEE into a float?

      it returns 0

      Comment

      • JimmyR.com

        #4
        Re: Turn binary number 0xFFFFFFEE into a float?

        Thanks for all the detail but the first thing I said was its a binary
        file. It's not FFFFFFEE ASCII. Someone else helped me figure it out
        though, here's a function I made

        function b2f($val) return floatval(hexdec (bin2hex($val)) );

        echo b2f(file_get_co ntents('testplz .bin'));

        Comment

        Working...