【问题标题】:How to convert 64 bit unsigned integer to Hex value in php?如何在php中将64位无符号整数转换为十六进制值?
【发布时间】:2021-05-11 13:29:39
【问题描述】:

我通过 API 将事件发布为 64 位无符号整数,需要使用 php 将其转换为十六进制值以识别发生的所有事件。

我收到的一些事件/整数示例如下所示; 80001000000 或 80010000000 或 80000000000

我正在寻找的输出/十六进制值在此图像(裁剪图像)中进行了解释:

【问题讨论】:

    标签: php integer 64-bit


    【解决方案1】:

    如果有人需要解决这个问题:

    <?php
    
    class Decoder {
    
        public static function decode($event) {
            $decimal = hexdec("$event");
            $binary = decbin("$decimal");
            $split_binary = str_split($binary);
            $binary_length = strlen($binary) - 1;
    
            $indicators = array();
            $index = 0;
            foreach ($split_binary as $letter) {
                if ($letter == '1')
                {
                    $signal = $binary_length - $index;
                    array_push($indicators, $signal);
                }
                $index ++;
            }
    
            return $indicators;
        }
    }
    
    $events = array('40010000000', '40002000000', '80000000000');
    
    foreach ($events as $event) {
        print_r(Decoder::decode($event));
    }
    
    ?>
    

    感谢软件的开发者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-13
      • 2017-09-04
      • 1970-01-01
      • 2016-03-08
      • 2014-04-11
      • 1970-01-01
      • 2020-03-17
      相关资源
      最近更新 更多