Number Systems Formulas
Mathematical formulas and algorithms for converting between different number systems and positional notations
1Positional Notation System
General Formula
Where:
- N = decimal value of the number
- dᵢ = digit at position i
- r = radix (base) of the number system
- i = position index (starting from 0 for rightmost digit)
- n = total number of digits
Extended Formula with Fractional Parts
For numbers with fractional parts:
Common Bases
Binary
Base 2
Digits: 0, 1
Octal
Base 8
Digits: 0-7
Decimal
Base 10
Digits: 0-9
Hexadecimal
Base 16
Digits: 0-9, A-F
2Base Conversion Algorithms
Any Base to Decimal
Algorithm: Horner's Method
Pseudocode:
result = 0 for each digit d from left to right: result = result × base + d return result
Decimal to Any Base
Algorithm: Repeated Division
Where qᵢ are quotients, r is the target base, and dᵢ are remainder digits.
Pseudocode:
digits = [] while N > 0: remainder = N mod base digits.prepend(remainder) N = N ÷ base return digits
3Binary System (Base 2)
Binary to Decimal
Example: (1101)₂ to decimal
Binary Arithmetic Operations
Binary Addition Rules
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (0 with carry 1)
Binary Multiplication Rules
- 0 × 0 = 0
- 0 × 1 = 0
- 1 × 0 = 0
- 1 × 1 = 1
Binary-Decimal Conversion Shortcuts
Powers of 2
2⁰ = 1
2¹ = 2
2² = 4
2³ = 8
2⁴ = 16
2⁵ = 32
2⁶ = 64
2⁷ = 128
2⁸ = 256
2⁹ = 512
2¹⁰ = 1024
2¹¹ = 2048
4Octal System (Base 8)
Octal to Decimal
Example: (157)₈ to decimal
Binary-Octal Conversion
Direct Conversion Method
Each octal digit corresponds to exactly 3 binary digits:
0₈ = 000₂
1₈ = 001₂
2₈ = 010₂
3₈ = 011₂
4₈ = 100₂
5₈ = 101₂
6₈ = 110₂
7₈ = 111₂
Powers of 8
8⁰ = 1
8¹ = 8
8² = 64
8³ = 512
8⁴ = 4,096
8⁵ = 32,768
5Hexadecimal System (Base 16)
Hexadecimal to Decimal
Example: (2AF)₁₆ to decimal
Hexadecimal Digits
0₁₆ = 0₁₀
1₁₆ = 1₁₀
2₁₆ = 2₁₀
3₁₆ = 3₁₀
4₁₆ = 4₁₀
5₁₆ = 5₁₀
6₁₆ = 6₁₀
7₁₆ = 7₁₀
8₁₆ = 8₁₀
9₁₆ = 9₁₀
A₁₆ = 10₁₀
B₁₆ = 11₁₀
C₁₆ = 12₁₀
D₁₆ = 13₁₀
E₁₆ = 14₁₀
F₁₆ = 15₁₀
Binary-Hexadecimal Conversion
Direct Conversion Method
Each hexadecimal digit corresponds to exactly 4 binary digits:
0₁₆ = 0000₂
1₁₆ = 0001₂
2₁₆ = 0010₂
3₁₆ = 0011₂
4₁₆ = 0100₂
5₁₆ = 0101₂
6₁₆ = 0110₂
7₁₆ = 0111₂
8₁₆ = 1000₂
9₁₆ = 1001₂
A₁₆ = 1010₂
B₁₆ = 1011₂
C₁₆ = 1100₂
D₁₆ = 1101₂
E₁₆ = 1110₂
F₁₆ = 1111₂
Powers of 16
16⁰ = 1
16¹ = 16
16² = 256
16³ = 4,096
16⁴ = 65,536
16⁵ = 1,048,576
6Fractional Number Conversions
Fractional Part to Decimal
Example: (0.101)₂ to decimal
Decimal Fraction to Any Base
Algorithm: Repeated Multiplication
Pseudocode:
fraction = decimal_part digits = [] while fraction ≠ 0 and precision not reached: fraction = fraction × base digit = floor(fraction) digits.append(digit) fraction = fraction - digit return "0." + digits
7Arithmetic in Different Bases
Addition in Base r
When the sum of digits ≥ r, carry 1 to the next position and subtract r from the sum.
Multiplication in Base r
Similar to decimal multiplication, but use base r for carries.
Quick Reference Table
Decimal | Binary | Octal | Hexadecimal |
---|---|---|---|
0 | 0 | 0 | 0 |
1 | 1 | 1 | 1 |
2 | 10 | 2 | 2 |
3 | 11 | 3 | 3 |
4 | 100 | 4 | 4 |
5 | 101 | 5 | 5 |
6 | 110 | 6 | 6 |
7 | 111 | 7 | 7 |
8 | 1000 | 10 | 8 |
9 | 1001 | 11 | 9 |
10 | 1010 | 12 | A |
11 | 1011 | 13 | B |
12 | 1100 | 14 | C |
13 | 1101 | 15 | D |
14 | 1110 | 16 | E |
15 | 1111 | 17 | F |
16 | 10000 | 20 | 10 |