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

后端 未结 10 1263
太阳男子
太阳男子 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:02

    // Conversion function
    function bin(nb)
    {
        return parseInt(nb.toString(2));
    }
    
    // Test
    var stop = false;
    while(!stop)
    {
        var n = parseInt(prompt("Type a decimal number : "));
        alert(bin(n));
    
        var str = prompt("Retry ? Y / N");
        if(str === "N") { stop = true; }
    }
    

提交回复
热议问题