jspωiki
Binary

Overview#

Binary (Base-2) is a Positional notation number system and typically a Data type and a Data representation

Specific details of the Data type Binary are context dependent.

Binary Numbers#

Binary numbers with only one bit set is easy to understand:

Binary RepresentationDecimal value
000000000000000000000000000000011
000000000000000000000000000000102
000000000000000000000000000001004
000000000000000000000000000010008
0000000000000000000000000001000016
0000000000000000000000000010000032
0000000000000000000000000100000064

Binary and Computers [1]#

When we write what is stored in a computer on paper, we normally use “0” for one of the states, and “1” for the other state. For example, a piece of computer memory could have the following voltages:
low low high low high high high high low high low low
We could allocate “0” to “low” (or False), and “1” to “high” (or True) and write this sequence down as:
0 0 1 0 1 1 1 1 0 1 0 0
While this notation is used extensively, and you may often hear the data being referred to as being “0’s and 1’s”, it is important to remember that a computer does not store 0’s and 1’s; it has no way of doing this. They are just using physical mechanisms such as "high" and "low" voltage, north or south polarity, and light or dark materials.

Converting Decimal to Binary#

JavaScript Example
function dec2bin(dec){
    return (dec >>> 0).toString(2);
}

Converting [{$pagename}] to Decimal#

JavaScript Example
function bin2dec(bin){
    return parseInt(bin, 2).toString(10);
}

More Information#

There might be more information for this subject on one of the following: