Number systems
Binary number system
How Modern Computers Use Binary
Modern computers rely on electricity to function. Inside a microchip, electricity is either turned on or off, which is represented by the symbols 1 and 0. This is known as binary. While many people know that computers work in binary, understanding how binary itself operates is key. Let’s break it down!
Decimal System (Base 10): How It Works
Before diving into binary, let’s understand our decimal system, also known as Base 10:
- 10 Symbols: The numbers 0 through 9.
- When you run out of symbols (after 9), you add another digit to the left.
- Each new digit to the left is 10 times greater than the digit to its right (thanks to positional notation).
This clever system allows us to represent an infinite range of numbers using just 10 symbols.
Binary System (Base 2): The Basics
Now, imagine working with only two symbols: 0 and 1. The same positional notation rules apply, but instead of multiplying by 10, each digit’s value is 2 times greater than the one to its right.
Example:
Binary Sequence: 10011011
- Multiply each digit by its positional value (powers of 2):
- (1 × 128) + (0 × 64) + (0 × 32) + (1 × 16) + (1 × 8) + (0 × 4) + (1 × 2) + (1 × 1)
- Total: 155 (in decimal)
Binary is essentially multiplication and addition in action.
Beyond Binary: Other Base Systems
There are many numbering systems besides Base 10 and Base 2, including:
- Base 3, Base 4, Base 8, Base 12, etc.
- All work on the same principle of positional notation.
Why Do We Use Base 10?
It’s likely because we have 10 fingers (digits). Historically, cultures like the Romans and Egyptians adopted Base 10 for this reason.
Interestingly, Base 8 and Base 12 are more efficient for simple calculations because they are more divisible than 10. However, transitioning to a new system now would be as difficult as convincing the U.S. to switch to the metric system!
Extending to Alphanumeric Characters
In systems with more than 10 digits (like Base 12 or Base 36), letters are used to represent numerals higher than 9:
- 10 = A, 11 = B, 12 = C, and so on.
For example:
- URL shorteners use alphanumeric systems to represent large numbers efficiently.
- Using both uppercase and lowercase letters can create systems like Base 62, which can represent up to 839 quadrillion values in just 10 digits!
Binary Addition
The rules for binary addition are:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 0 (with carry 1)
- 1 + 1 + 1 = 1 (with carry 1)
Example: Adding Two Binary Numbers
Given:
- First Number: 1101.101
- Second Number: 111.011
Steps:
- Align the binary numbers:
1101.101
-
0111.011
- Perform the addition:
- Starting from the rightmost bit:
- 1 + 1 = 0 (carry 1)
- 0 + 1 + carry 1 = 0 (carry 1)
- 1 + 0 + carry 1 = 1 (carry 0)
- Continue bit by bit and propagate the carry as needed.
- Starting from the rightmost bit:
Result: The final sum is 1 0100.000
.
Binary Subtraction
The rules for binary subtraction are:
- 0 − 0 = 0
- 1 − 1 = 0
- 1 − 0 = 1
- 0 − 1 = 1 (with borrow 1)
Example: Subtracting Two Binary Numbers
Given:
- First Number: 1010.01
- Second Number: 111.111
Steps:
- Align the binary numbers:
1010.010
-
0111.111
- Perform the subtraction:
- Borrow from higher bits as needed.
- Example: 0 − 1 = 1 (with borrow 1).
Result: The final difference is 0010.001
.
Binary Multiplication
The rules for binary multiplication are:
- 0 × 0 = 0
- 0 × 1 = 0
- 1 × 0 = 0
- 1 × 1 = 1
Example: Multiplying Two Binary Numbers
Given:
- First Number: 1101
- Second Number: 110
Steps:
- Multiply each bit of the second number with the first number, just like in decimal multiplication.
- Align the partial products based on their positions.
1101
× 0110
Partial Products:
- 1101 × 0 = 0000
- 1101 × 1 = 1101 (shifted 1 position)
- 1101 × 1 = 1101 (shifted 2 positions)
3. Add the partial products to get the final result.
**Result:** The product is `1000110`.
---
### **Binary Division**
Binary division follows the **long division method**, similar to decimal division.
#### **Example: Dividing Two Binary Numbers**
Given:
- **Dividend:** 101101
- **Divisor:** 110
**Steps**:
1. Compare the divisor with the most significant bits of the dividend.
2. Perform subtraction (binary) and bring down the next bit from the dividend.
3. Repeat until all bits are processed.
**Result:**
- Quotient: `111`
- Remainder: `01`
---
### **Summary**
In this lecture, we covered:
1. **Addition**: Using basic binary addition rules.
2. **Subtraction**: Borrowing when needed.
3. **Multiplication**: Similar to decimal, with aligned partial products.
4. **Division**: Using the long division method.
Thank you for joining us! We hope you found this session informative.
Stay tuned for more topics on **RF Design Basics**.
---
Understanding the Octal Number System
What is the Octal Number System?
The octal number system uses 8 symbols:
0, 1, 2, 3, 4, 5, 6, and 7.
- Base: The base of the system is 8, which is why it is called the Octal Number System.
- The name “octal” pertains to its base value of 8.
Octal and Binary Relationship
The octal number system has a special relationship with 3-bit binary numbers. Each 3-bit binary number can represent one octal symbol.
Example of Binary to Octal Conversion:
Binary | Octal | Explanation |
---|---|---|
000 | 0 | All bits are 0. |
001 | 1 | A “1” appears in the 2⁰ place. |
010 | 2 | A “1” appears in the 2¹ place. |
011 | 3 | Add 2¹ + 2⁰ → 2 + 1 = 3. |
100 | 4 | A “1” appears in the 2² place. |
101 | 5 | Add 2² + 2⁰ → 4 + 1 = 5. |
110 | 6 | Add 2² + 2¹ → 4 + 2 = 6. |
111 | 7 | Add 2² + 2¹ + 2⁰ → 4 + 2 + 1 = 7. |
Simplifying Binary Bit Streams with Octal
The octal system helps in compactly representing long binary bit streams.
Example:
- Binary Stream:
100111011010010
(Base 2) - Steps to Convert to Octal:
- Divide the binary stream into groups of 3 bits, starting from the LSB (Least Significant Bit):
100 111 011 010 010
. - Replace each group with its equivalent octal value:
100
→ 4111
→ 7011
→ 3010
→ 2010
→ 2
- Final Octal Value: 47322 (Base 8).
- Divide the binary stream into groups of 3 bits, starting from the LSB (Least Significant Bit):
Octal Number Formation
In the octal system:
- Numbers are formed by reusing the 8 symbols (0–7).
- After exhausting all symbols, the next digit is introduced.
Example Sequence:
- Single-Digit Octal Numbers: 0, 1, 2, 3, 4, 5, 6, 7.
- Next Numbers:
- After 7 → 10 (not called “ten”; it’s 1 0 in base 8).
- After 17 → 20 (similar pattern).
- After 77 → 100 (a new place value is introduced).
General Representation of Octal Numbers
For a 5-digit octal number:
- The base is 8.
- Each place has a value of 8 raised to the power of its position:
- Rightmost digit: 8⁰ → 1.
- Next digit: 8¹ → 8.
- Then 8² → 64, and so on.
Example:
For the octal number 12345 (Base 8):
- Its value in decimal is calculated as:
1 × 8⁴ + 2 × 8³ + 3 × 8² + 4 × 8¹ + 5 × 8⁰.
Questions for You!
- What comes after 767 in octal?
- What comes before 440 in octal?
Conversions
1. Octal to Decimal
To convert an octal number to a decimal, multiply each digit by its positional weight (powers of 8) and sum them.
Example: Convert 2348234_8 to decimal.
2348=2×82+3×81+4×80=2×64+3×8+4×1=128+24+4=15610234_8 = 2 \times 8^2 + 3 \times 8^1 + 4 \times 8^0 = 2 \times 64 + 3 \times 8 + 4 \times 1 = 128 + 24 + 4 = 156_{10}
2. Decimal to Octal
To convert a decimal number to octal:
- Divide the number by 8 and record the remainder.
- Continue dividing until the quotient is 0.
- Write the remainders in reverse order.
Example: Convert 15610156_{10} to octal.
- 156÷8=19156 \div 8 = 19 remainder 44
- 19÷8=219 \div 8 = 2 remainder 33
- 2÷8=02 \div 8 = 0 remainder 22
Result: 15610=2348156_{10} = 234_8.
3. Octal to Binary
Convert each octal digit to its 3-bit binary equivalent.
Example: Convert 2348234_8 to binary.
- 28=01022_8 = 010_2, 38=01123_8 = 011_2, 48=10024_8 = 100_2
- Combine: 2348=0100111002234_8 = 010011100_2.
4. Binary to Octal
Group binary digits into groups of 3 from right to left and convert each group to its octal equivalent.
Example: Convert 1011102101110_2 to octal.
- Group: 101,110101, 110
- Convert: 1012=58,1102=68101_2 = 5_8, 110_2 = 6_8
- Result: 1011102=568101110_2 = 56_8.
Octal Arithmetic Operations
1. Octal Addition
The rules of octal addition are the same as decimal addition, but a carry is generated whenever the sum exceeds 7.
Rules:
- 0+0=00 + 0 = 0
- 5+3=85 + 3 = 8, write 00 and carry 11.
- 7+6=13107 + 6 = 13_{10}, write 55 and carry 11.
Example: Add 258+36825_8 + 36_8.
- Add the rightmost digits: 5+6=13105 + 6 = 13_{10} → 13−8=513 – 8 = 5 (write 55, carry 11).
- Add the left digits: 2+3+1=62 + 3 + 1 = 6.
Result: 258+368=65825_8 + 36_8 = 65_8.
2. Octal Subtraction
Subtraction in octal follows similar rules to decimal subtraction. Borrow is taken when needed.
Rules:
- 0−0=00 – 0 = 0
- 7−3=47 – 3 = 4
- 4−6=64 – 6 = 6 (borrow 11).
Example: Subtract 658−34865_8 – 34_8.
- Subtract the rightmost digits: 5−4=15 – 4 = 1.
- Subtract the left digits: 6−3=36 – 3 = 3.
Result: 658−348=31865_8 – 34_8 = 31_8.
3. Octal Multiplication
The multiplication rules for octal are the same as decimal, but the product of two digits must be converted back to octal if it exceeds 7.
Rules:
- 2×3=62 \times 3 = 6
- 5×4=2010=2485 \times 4 = 20_{10} = 24_8.
Example: Multiply 258×3825_8 \times 3_8.
- Multiply 5×3=15105 \times 3 = 15_{10} → 15−8=715 – 8 = 7 (write 77, carry 11).
- Multiply 2×3+1=72 \times 3 + 1 = 7.
Result: 258×38=77825_8 \times 3_8 = 77_8.
4. Octal Division
For octal division, divide as in decimal and convert remainders back to octal when needed.
Example: Divide 3458÷58345_8 \div 5_8.
- Perform long division:
- 348÷58=6834_8 \div 5_8 = 6_8 (remainder 44).
- Bring down the next digit.
- 458÷58=11845_8 \div 5_8 = 11_8 (remainder 00).
Result: Quotient = 61861_8.
Summary
Operation | Example | Result |
---|---|---|
Octal to Decimal | 2348→?10234_8 \to ?_{10} | 15610156_{10} |
Decimal to Octal | 15610→?8156_{10} \to ?_8 | 2348234_8 |
Addition | 258+36825_8 + 36_8 | 65865_8 |
Subtraction | 658−34865_8 – 34_8 | 31831_8 |
Multiplication | 258×3825_8 \times 3_8 | 77877_8 |
Division | 3458÷58345_8 \div 5_8 | 61861_8 |
Understanding the Hexadecimal Number System
Why is it called the Hexadecimal Number System?
The hexadecimal number system uses 16 symbols:
- 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 (same as decimal).
- A, B, C, D, E, and F (to represent values from 10 to 15).
The name hexadecimal comes from:
- Hexa: Meaning 6.
- Decimal: Meaning 10.
Thus, the system combines 6 + 10 = 16 symbols.
Unlike decimal, which moves to the next place after 9, hexadecimal continues with A, B, C, D, E, and F, giving it a base of 16.
Hexadecimal and Binary: A Strong Relationship
In hexadecimal, every 4-bit binary number corresponds to a single hexadecimal digit. Let’s break it down:
Binary to Hexadecimal Conversion Table:
Binary | Decimal | Hexadecimal |
---|---|---|
0000 | 0 | 0 |
0001 | 1 | 1 |
0010 | 2 | 2 |
0011 | 3 | 3 |
0100 | 4 | 4 |
0101 | 5 | 5 |
0110 | 6 | 6 |
0111 | 7 | 7 |
1000 | 8 | 8 |
1001 | 9 | 9 |
1010 | 10 | A |
1011 | 11 | B |
1100 | 12 | C |
1101 | 13 | D |
1110 | 14 | E |
1111 | 15 | F |
Example: Converting Binary to Hexadecimal
Consider this 16-bit binary number: 1010 1001 1110 1100
Steps:
- Group the binary number into 4-bit sections from LSB (Least Significant Bit) to MSB (Most Significant Bit):
1010
,1001
,1110
,1100
- Convert each group to hexadecimal:
1010
→ A1001
→ 91110
→ E1100
→ C
Result:A9EC
Alternate Representation:
- Add a 0x prefix:
0xA9EC
- The 0x indicates that the number is in hexadecimal.
Practical Use of Hexadecimal Numbers
Hexadecimal numbers simplify the representation of binary bit streams:
- Binary:
1010100111101100
(16 bits) - Hexadecimal:
A9EC
(4 digits)
This efficiency makes hexadecimal widely used in memory addressing, machine-level programming, and data representation.
How Numbers are Formed in Hexadecimal
- Start with the 16 symbols:
0–9
andA–F
. - After F, increment the next significant digit:
F
→10
10
→11
11
→12
… up to1F
.
- When all combinations for a place are used, add a new place:
FF
→100
.
Place Values:
- Similar to decimal, hexadecimal uses powers of its base (16):
- 16⁰ (1) for the least significant digit.
- 16¹ (16) for the next place.
- 16² (256), 16³ (4096), and so on.
General Representation
Consider a 5-digit hexadecimal number:
ABCDE
Each place can have any value from 0–F
:
- The base is 16.
- Place values:
- 16⁴, 16³, 16², 16¹, 16⁰.
To find the decimal value, multiply each digit by its corresponding place value and sum them.
Challenge for You
- What comes before and after the hexadecimal number
CE9A
?
Conversions
1. Hexadecimal to Decimal
To convert a hexadecimal number to decimal:
- Multiply each digit by its positional weight (160,161,162,…16^0, 16^1, 16^2, \dots) and sum the results.
Example: Convert 2F3162F3_{16} to decimal.
2F316=2×162+F×161+3×160=2×256+15×16+3=512+240+3=75510.2F3_{16} = 2 \times 16^2 + F \times 16^1 + 3 \times 16^0 = 2 \times 256 + 15 \times 16 + 3 = 512 + 240 + 3 = 755_{10}.
2. Decimal to Hexadecimal
To convert a decimal number to hexadecimal:
- Divide the number by 16, record the remainder, and continue dividing until the quotient is 0.
- Write the remainders in reverse order.
Example: Convert 75510755_{10} to hexadecimal.
- 755÷16=47755 \div 16 = 47 remainder 33.
- 47÷16=247 \div 16 = 2 remainder 15(F)15 (F).
- 2÷16=02 \div 16 = 0 remainder 22.
Result: 75510=2F316755_{10} = 2F3_{16}.
3. Hexadecimal to Binary
Convert each hexadecimal digit to its 4-bit binary equivalent.
Example: Convert 2F3162F3_{16} to binary.
- 2=00102 = 0010, F=1111F = 1111, 3=00113 = 0011.
- Combine: 2F316=0010 1111 001122F3_{16} = 0010\ 1111\ 0011_2.
4. Binary to Hexadecimal
Group binary digits into groups of 4 from right to left and convert each group to its hexadecimal equivalent.
Example: Convert 101111001121011110011_2 to hexadecimal.
- Group: 10 1111 001110\ 1111\ 0011.
- Add leading zeros if needed: 0010 1111 00110010\ 1111\ 0011.
- Convert: 0010=2,1111=F,0011=30010 = 2, 1111 = F, 0011 = 3.
Result: 10111100112=2F3161011110011_2 = 2F3_{16}.
Hexadecimal Arithmetic Operations
1. Hexadecimal Addition
The rules for hexadecimal addition are the same as decimal, but carry is generated whenever the sum exceeds 1515 (FF).
Rules:
- A+5=FA + 5 = F
- F+1=1016F + 1 = 10_{16} (carry 11).
Example: Add 1A16+B5161A_{16} + B5_{16}.
- Add the rightmost digits: A+5=FA + 5 = F.
- Add the next digits: 1+B=C161 + B = C_{16}.
Result: 1A16+B516=CF161A_{16} + B5_{16} = CF_{16}.
2. Hexadecimal Subtraction
For hexadecimal subtraction, borrow is needed when subtracting a larger digit from a smaller one.
Rules:
- C−5=7C – 5 = 7
- A – F = B (borrow \(1)).
Example: Subtract B516−1A16B5_{16} – 1A_{16}.
- Subtract the rightmost digits: 5−A=B5 – A = B (borrow 11).
- Subtract the next digits: B−1−1=9B – 1 – 1 = 9.
Result: B516−1A16=9B16B5_{16} – 1A_{16} = 9B_{16}.
3. Hexadecimal Multiplication
For hexadecimal multiplication, multiply as in decimal and convert the product to hexadecimal.
Rules:
- A×5=5016A \times 5 = 50_{16}
- F×3=2D16F \times 3 = 2D_{16} (convert 451045_{10} to hexadecimal).
Example: Multiply 1A16×3161A_{16} \times 3_{16}.
- Multiply A×3=1E16A \times 3 = 1E_{16} (write EE, carry 11).
- Multiply 1×3+1=41 \times 3 + 1 = 4.
Result: 1A16×316=4E161A_{16} \times 3_{16} = 4E_{16}.
4. Hexadecimal Division
For hexadecimal division, perform long division as in decimal and convert remainders to hexadecimal when needed.
Example: Divide 2F316÷B162F3_{16} \div B_{16}.
- Convert to decimal: 2F316=75510,B16=11102F3_{16} = 755_{10}, B_{16} = 11_{10}.
- Perform the division in decimal: 755÷11=68755 \div 11 = 68 remainder 77.
- Convert the quotient back to hexadecimal: 6810=441668_{10} = 44_{16}.
Result: 2F316÷B16=44162F3_{16} \div B_{16} = 44_{16} with remainder 710=7167_{10} = 7_{16}.
Summary
Operation | Example | Result |
---|---|---|
Hex to Decimal | 2F316→?102F3_{16} \to ?_{10} | 75510755_{10} |
Decimal to Hex | 75510→?16755_{10} \to ?_{16} | 2F3162F3_{16} |
Addition | 1A16+B5161A_{16} + B5_{16} | CF16CF_{16} |
Subtraction | B516−1A16B5_{16} – 1A_{16} | 9B169B_{16} |
Multiplication | 1A16×3161A_{16} \times 3_{16} | 4E164E_{16} |
Division | 2F316÷B162F3_{16} \div B_{16} | 441644_{16} |