Bytes are converted to float (php)

How can I convert from bytes to float in php? Like in Java

int i = (byte3 & 0xff) << 24 | (byte2 & 0xff) << 16 | (byte1 & 0xff) << 8 | byte0 & 0xff; Float.intBitsToFloat(i); 
+2
floating-point php byte
Apr 12 '10 at 19:41
source share
3 answers

There may be a more direct path, but here you go:

 <?php var_dump(unpack('f', pack('i', 1059760811))); ?> 

This, of course, depends on the machine, but I don’t know a single machine running PHP that does not use IEEE 754 floats.

+5
Apr 12 '10 at 20:14
source share

I don't think php has bytes, right? When you assign a number to a variable, you will get a variable with a number type

 $a = 10; // integer $f = 1.0; // double $b = $a + $f; // $b is double 
0
Apr 12 2018-10-12T00:
source share

If I understand you correctly, do you want to take a raw 32- or 64-bit integer value and force this bit set to process instead of a floating-point number?

Try pack 'and unpack ' functions

0
Apr 12 '10 at 20:15
source share



All Articles