【问题标题】:Printing a two's complement binary string of an 8 bit byte in javascript在javascript中打印一个8位字节的二进制补码字符串
【发布时间】:2018-10-11 17:50:29
【问题描述】:

在 javascript 中打印一个 8 位字节的二进制补码字符串。

今天必须这样做,但在第一页上没有找到答案,所以我分享一下,以防万一有人需要。

【问题讨论】:

    标签: javascript formatting byte string-formatting twos-complement


    【解决方案1】:
    function printByteToBinary(n) {
        n = n < 0 ? n + 256 : n;
        return ("00000000" + n.toString(2)).slice(-8);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      相关资源
      最近更新 更多