字节转换为浮点数(php)

2022-01-09 00:00:00 floating-point byte php

如何在 php 中将字节转换为浮点数?就像在 Java 中一样

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

推荐答案

可能有更直接的方法,但是给你:

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

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

当然,这取决于机器,但我不知道任何运行 PHP 的机器不使用 IEEE 754 浮点数.

This is, of course, machine dependent, but I don't know of any machine running PHP that doesn't use IEEE 754 floats.

相关文章