簡體   English   中英

如何將 64 位無符號 integer 轉換為 php 中的十六進制值?

[英]How to convert 64 bit unsigned integer to Hex value in php?

我通過 API 將事件發布為 64 位無符號整數,需要使用 php 將其轉換為十六進制值以識別發生的所有事件。

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

我正在尋找的輸出/十六進制值在此圖像(裁剪圖像)中進行了解釋:

在此處輸入圖像描述

如果有人需要解決此問題:

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

?>

歸功於軟件的開發者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM