Last updated
How Binary Numbers Work
Binary is a base-2 number system that uses only two digits: 0 and 1. Every digital computer stores and processes all data — text, images, audio, code — as sequences of binary digits (bits). Understanding binary-to-decimal conversion is fundamental to computer science, networking, and low-level programming.
In decimal (base 10), each digit position represents a power of 10. In binary (base 2), each position represents a power of 2, starting from 20 = 1 on the right.
Step-by-Step Conversion
To convert binary 1011010 to decimal:
Position: 6 5 4 3 2 1 0
Bit: 1 0 1 1 0 1 0
Power: 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Value: 64 0 16 8 0 2 0
Sum: 64 + 16 + 8 + 2 = 90
So binary 1011010 = decimal 90
Common Binary Values Reference
| Binary | Decimal | Hex | Notes |
|---|---|---|---|
0000 0000 | 0 | 0x00 | Null byte |
0100 0001 | 65 | 0x41 | ASCII 'A' |
0110 0001 | 97 | 0x61 | ASCII 'a' |
0111 1111 | 127 | 0x7F | Max 7-bit value / DEL |
1000 0000 | 128 | 0x80 | First bit of high byte |
1111 1111 | 255 | 0xFF | Max 8-bit unsigned value |
1111 1111 1111 1111 | 65535 | 0xFFFF | Max 16-bit unsigned value |
Binary in Programming
Most languages let you write binary literals directly using a 0b prefix.
Bitwise operators work directly on the binary representation:
// Binary literals
const a = 0b1010; // 10
const b = 0b0110; // 6
// Bitwise AND — both bits must be 1
console.log(a & b); // 0b0010 = 2
// Bitwise OR — either bit can be 1
console.log(a | b); // 0b1110 = 14
// Bitwise XOR — bits must differ
console.log(a ^ b); // 0b1100 = 12
// Left shift — multiply by 2^n
console.log(1 << 4); // 16 (1 shifted left 4 positions)
// Right shift — divide by 2^n
console.log(64 >> 2); // 16
// Convert decimal to binary string
(90).toString(2); // "1011010"
// Convert binary string to decimal
parseInt('1011010', 2); // 90
Two's Complement: Negative Numbers in Binary
Computers represent negative integers using two's complement.
To negate a number: flip all bits, then add 1.
For example, -5 in 8-bit two's complement:
+5 = 0000 0101
Flip = 1111 1010
Add 1= 1111 1011 ← this is -5 in two's complement
Range of 8-bit signed integer: -128 to +127
Range of 8-bit unsigned integer: 0 to 255