Specific details of the Data type Binary are context dependent.
Binary Representation | Decimal value |
---|---|
00000000000000000000000000000001 | 1 |
00000000000000000000000000000010 | 2 |
00000000000000000000000000000100 | 4 |
00000000000000000000000000001000 | 8 |
00000000000000000000000000010000 | 16 |
00000000000000000000000000100000 | 32 |
00000000000000000000000001000000 | 64 |
low low high low high high high high low high low lowWe 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 0While 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.
function dec2bin(dec){ return (dec >>> 0).toString(2); }
function bin2dec(bin){ return parseInt(bin, 2).toString(10); }