Binary Number System

Understanding Base 2 - The Language of Computers

What is Binary?
Definition
Binary = base 2 number system.
Uses only two digits: 0 and 1.
Each position (bit) represents a power of 2.
All information inside a computer (numbers, letters, images, sound) is ultimately represented in binary (0s and 1s).
Example
Binary (1011)₂ = (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2⁰)
= 8 + 0 + 2 + 1 = 11 in decimal
Binary Digits (Bits & Bytes)
Bit
A single binary digit (0 or 1)
Nibble
4 bits (e.g., 1010)
Byte
8 bits (e.g., 11001010)
Word
Group of bytes (depends on CPU, e.g., 32-bit word = 4 bytes)
Example
The letter 'A' in ASCII is 65 decimal, which is 01000001₂ (8 bits).
Binary Representation of Data
Numbers
Stored directly as binary values
Characters
ASCII or Unicode codes stored in binary
Images
Stored as pixels, each pixel's color in binary (e.g., RGB values)
Sound
Stored as samples, each sample in binary
Example
'B' = 66₁₀ = 01000010₂
Conversions with Binary
Decimal → Binary
Method: Division by 2
1
25 ÷ 2 = 12 remainder 1
2
12 ÷ 2 = 6 remainder 0
3
6 ÷ 2 = 3 remainder 0
4
3 ÷ 2 = 1 remainder 1
5
1 ÷ 2 = 0 remainder 1
Reading remainders bottom → top: 11001₂
So, 25₁₀ = 11001₂
Binary → Decimal
Method: Multiplication by powers of 2
Convert 10110₂ to decimal:
(1 × 2⁴) + (0 × 2³) + (1 × 2²) + (1 × 2¹) + (0 × 2⁰)
= (1 × 16) + (0 × 8) + (1 × 4) + (1 × 2) + (0 × 1)
= 16 + 0 + 4 + 2 + 0 = 22₁₀
Binary → Hexadecimal
Method: Grouping into 4 bits
Convert 11010110₂ to hex:
Group into 4 bits: 1101 0110
1101₂ = 13₁₀ = D₁₆
0110₂ = 6₁₀ = 6₁₆
So, 11010110₂ = D6₁₆
Hexadecimal → Binary
Method: Convert each hex digit to 4-bit binary
Convert A3₁₆ to binary:
A₁₆ = 10₁₀ = 1010₂
3₁₆ = 3₁₀ = 0011₂
So, A3₁₆ = 1010 0011₂
Binary Fractions
Method: Multiply by 2 repeatedly
Convert 0.625₁₀ to binary:
0.625 × 2 = 1.25 → 1
0.25 × 2 = 0.5 → 0
0.5 × 2 = 1.0 → 1
So, 0.625₁₀ = 0.101₂
Binary Arithmetic
Binary Addition
Add Result Carry
0 + 0 0 0
0 + 1 1 0
1 + 0 1 0
1 + 1 0 1
Example: (1011)₂ + (1101)₂
Adding: 11₁₀ + 13₁₀ = 24₁₀
1011
+ 1101
-------
11000
1
Rightmost bits: 1 + 1 = 0, carry 1
2
Next bits: 1 + 0 + carry 1 = 0, carry 1
3
Next bits: 0 + 1 + carry 1 = 0, carry 1
4
Leftmost bits: 1 + 1 + carry 1 = 1, carry 1
5
Write down final carry: 1
Result: (1011)₂ + (1101)₂ = 11000₂ = 24₁₀
Binary Subtraction
Subtract Result Borrow?
0 − 0 0 No
1 − 0 1 No
1 − 1 0 No
0 − 1 1 Yes, borrow 1
Example: (1010)₂ − (0111)₂
Subtracting: 10₁₀ − 7₁₀ = 3₁₀
1010
- 0111
-------
0011
1
Rightmost bits: 0 − 1 → borrow → 10 − 1 = 1
2
Next bits: 0 − 1 (after borrow) → borrow again → 10 − 1 = 1
3
Next bits: 0 − 1 (after borrow) → borrow again → 10 − 1 = 1
4
Leftmost bits: 0 − 0 (after borrow) = 0
Result: (1010)₂ − (0111)₂ = 0011₂ = 3₁₀
Binary Multiplication
Multiply Result
0 × 0 0
0 × 1 0
1 × 0 0
1 × 1 1
Example: (101)₂ × (11)₂
Multiplying: 5₁₀ × 3₁₀ = 15₁₀
101
× 11
-----
101 (101 × 1)
+ 1010 (101 × 1, shifted left)
-----
1111
1
Multiply 101 × 1 (rightmost bit) = 101
2
Multiply 101 × 1 (next bit) = 101, shift left by 1 position = 1010
3
Add the results: 101 + 1010 = 1111
Result: (101)₂ × (11)₂ = 1111₂ = 15₁₀
Binary Division
Example: (1100)₂ ÷ (10)₂
Dividing: 12₁₀ ÷ 2₁₀ = 6₁₀
110
_____
10 ) 1100
10
--
10
10
--
00
1
10 goes into 11 → 1 time, write 1
2
1 × 10 = 10, subtract from 11 → 01
3
Bring down next bit → 10
4
10 goes into 10 → 1 time, write 1
5
1 × 10 = 10, subtract from 10 → 00
6
Bring down next bit → 00
7
10 goes into 00 → 0 times, write 0
Result: (1100)₂ ÷ (10)₂ = 110₂ = 6₁₀
Signed Binary Numbers
What Does "Signed" Mean?
In computing, a signed binary number can be positive or negative.
To represent negative numbers, we use something called Two's Complement.
Unsigned binary = only positive numbers (e.g., 0 to 255 in 8 bits)
Signed binary (Two's Complement) = both positive and negative numbers (e.g., −128 to +127 in 8 bits)
Why Use Two's Complement?
  • It allows using the same adder hardware for both addition and subtraction
  • There's only one representation for zero (unlike sign-magnitude)
  • It simplifies logic and makes overflow detection easier
How to Represent a Negative Number Using Two's Complement
1
Step 1: Write +5 in binary (8 bits)
+5 = 00000101₂
2
Step 2: Invert (flip) all bits
00000101 → 11111010
This is called the 1's Complement of 5
3
Step 3: Add 1
11111010
+ 1
---------
11111011
This is the Two's Complement of +5, and it's how the computer stores −5
Final Answer: −5 in 8-bit two's complement = 11111011₂
Advantages of Binary
Simplicity
Very simple (only 0 & 1), making it easy for computers to process
Hardware Implementation
Easy for computers to store and process (voltage: 0 = OFF, 1 = ON)
Reliability
Less chance of error compared to decimal signals
Applications of Binary
Digital Circuits
Transistors are ON (1) or OFF (0)
Memory Storage
Each memory cell stores a bit
Networking
IP addresses (e.g., 192.168.1.1 in binary)
Programming
Machine code is binary instructions
Example
The ASCII code for letter C = 67₁₀ = 01000011₂ — stored in memory as 8 bits.
Summary
Binary = base 2 (digits 0,1). It's the fundamental language of all computers.
Binary = base 2 (0,1)
Conversions: decimal ↔ binary ↔ hex ↔ octal
Supports arithmetic (add, sub, mul, div)
Negative numbers use two's complement
Binary is the language of all computers