The Decimal Number System (Base 10)
The decimal number system uses 10 digits (0-9). Each position represents a power of 10:
Example: 423 = 4×10² + 2×10¹ + 3×10⁰ = 400 + 20 + 3
The Binary Number System (Base 2)
The binary number system uses only 2 digits (0 and 1). Each position represents a power of 2:
Example: 101 = 1×2² + 0×2¹ + 1×2⁰ = 4 + 0 + 1 = 5
Converting Decimal to Binary
Method 1: Division by 2
- Divide the decimal number by 2.
- Get the integer quotient for the next iteration.
- Get the remainder for the binary digit.
- Repeat until the quotient becomes 0.
- The binary digits are read from bottom to top.
Example: Convert 42 to binary
| Division |
Quotient |
Remainder (Binary Digit) |
| 42 ÷ 2 | 21 | 0 |
| 21 ÷ 2 | 10 | 1 |
| 10 ÷ 2 | 5 | 0 |
| 5 ÷ 2 | 2 | 1 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Reading from bottom to top: 101010
Fractional Decimal to Binary
For numbers with fractional parts:
- Convert the integer part using the method above.
- For the fractional part, repeatedly multiply by 2.
- The integer part of the result is the binary digit.
- Continue with the fractional part of the result until precision is reached.
Negative Numbers (Two's Complement)
Two's complement is used to represent negative numbers in binary:
- Convert the absolute value to binary.
- Invert all bits (change 0 to 1 and 1 to 0).
- Add 1 to the result.