How to see binary representation of variable

前端 未结 7 1307
醉梦人生
醉梦人生 2020-12-19 00:07

Is there any possibility to see binary representation of variable?

相关标签:
7条回答
  • 2020-12-19 00:25

    Another solution:

    function d2b($dec, $n = 16) {
        return str_pad(decbin($dec), $n, "0", STR_PAD_LEFT);
    }
    

    Example:

    // example:
    echo d2b(E_ALL);
    echo d2b(E_ALL | E_STRICT);
    echo d2b(0xAA55);
    echo d2b(5);
    
    Output:
    0111011111111111
    0111111111111111
    1010101001010101
    0000000000000101
    
    0 讨论(0)
提交回复
热议问题