Is there “0b” or something similar to represent a binary number in Javascript

后端 未结 10 1259
太阳男子
太阳男子 2020-11-29 02:32

I know that 0x is a prefix for hexadecimal numbers in Javascript. For example, 0xFF stands for the number 255.

Is there something similar f

10条回答
  •  情话喂你
    2020-11-29 03:08

    If your primary concern is display rather than coding, there's a built-in conversion system you can use:

    var num = 255;
    document.writeln(num.toString(16)); // Outputs: "ff"
    document.writeln(num.toString(8)); // Outputs: "377"
    document.writeln(num.toString(2)); // Outputs: "11111111"
    

    Ref: JavaScript Number Reference

提交回复
热议问题