字节转换为浮点数(php) [英] bytes convert to float (php)

查看:15
本文介绍了字节转换为浮点数(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.

这篇关于字节转换为浮点数(php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆