dongwopu8210 2012-07-01 12:23
浏览 78
已采纳

如何在32位php上获得64位数的按位结果

I have two 32-bit unsigned integers in php (the result of crc32() ) and I want to get the bitwise result of these numbers on a 32 bit version of php.

I have tried many experiments, but evidently there is something I am missing about how php handles these numbers and binary data.

Update:

I am looking for something like this:

$x = crc32("abc");
$bin = sprintf("%b", $x);

$x2    = crc32("abc2");
$bin2 = sprintf("%b", $x2);

$b = $bin | $bin2;


$result = sprintf("%u",$b);

var_dump($result);

That code does not work, but by replacing %b and %u with the right numbers I think it could work

  • 写回答

2条回答 默认 最新

  • duanbei2914 2012-07-01 12:28
    关注

    Simply use the the bitwise OR | instead of the logical one, ||:

    $x  = crc32("abc");
    $x2 = crc32("abc2");
    $b = $x | $x2;              // The integer 2142140882
    $result = sprintf('%u',$b); // The string "2142140882"
    

    If you want to get a binary string of this result, use pack:

    $result_binary = pack('N', $b); // Binary format, "\x7f\xae\x79\d2"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错