开发者

How To Convert double/binary and vice versa?

开发者 https://www.devze.com 2023-01-25 06:40 出处:网络
I would like to convert 14.4689 or 13.3开发者_StackOverflow616 to binary data (bits) in php. How Can I do this?

I would like to convert 14.4689 or 13.3开发者_StackOverflow616 to binary data (bits) in php. How Can I do this?

Thanks for helping

Stephane


Use pack('d',14.4689) (double) or pack('f',14.4689) (float)


look at the pack and unpack functions.

[adding example]


jcomeau@intrepid:~/rentacoder/harvard$ cat /tmp/test.php; /tmp/test.php
#!/usr/bin/php5-cgi
<?php
$packed = pack("d", 12.3456);
print_r(unpack("d", $packed));
?>
X-Powered-By: PHP/5.2.12-2
Content-type: text/html

Array
(
    [1] => 12.3456
)


use this :

<?php
decbin(14.4689);
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消