Number System - Final 1 - PDF

Document Details

COMSATS Institute of Information Technology

COMSATS

Rab Nawaz Khan Jadoon

Tags

number systems computer science conversion techniques number theory

Summary

This document provides a detailed explanation of number systems, including decimal, binary, octal, and hexadecimal representations. It covers conversion techniques between these different systems as well as practical examples.

Full Transcript

# Number System ## Rab Nawaz Khan Jadoon Lecturer COMSATS Lahore Department of Computer Science DCS COMSATS Institute of Information Technology ## Computing for Management ## Common Number Systems | System | Base | Symbols | Used by humans? | Used in computers? | |---...

# Number System ## Rab Nawaz Khan Jadoon Lecturer COMSATS Lahore Department of Computer Science DCS COMSATS Institute of Information Technology ## Computing for Management ## Common Number Systems | System | Base | Symbols | Used by humans? | Used in computers? | |--------------|------|------------------------------|-----------------|--------------------| | Decimal | 10 | 0, 1, ..., 9 | Yes | No | | Binary | 2 | 0, 1 | No | Yes | | Octal | 8 | 0, 1, ..., 7 | No | No | | Hexadecimal | 16 | 0, 1, ..., 9, A, B, ..., F | No | Yes | ## Quantities/Counting ### (1 of 3) | 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 | ### (2 of 3) | Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 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 | ### (3 of 3) | Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 16 | 10000 | 20 | 10 | | 17 | 10001 | 21 | 11 | | 18 | 10010 | 22 | 12 | | 19 | 10011 | 23 | 13 | | 20 | 10100 | 24 | 14 | | 21 | 10101 | 25 | 15 | | 22 | 10110 | 26 | 16 | | 23 | 10111 | 27 | 17 | | ... | ... | ... | ... | ## Conversion Among Bases - The possibilities: ![Conversion Among Bases diagram](Conversion Among Bases diagram) ## Quick Example $25_{10} = 11001_2 = 31_8 = 19_{16}$ This is a simple conversion from Decimal to Binary, Octal, and Hexadecimal demonstrating the concept of bases. ## Decimal to Decimal (just for fun) ![Decimal to Decimal diagram](Decimal to Decimal diagram) It's a self-conversion which is used to demonstrate base and weight concepts. ## Decimal to Binary ![Decimal to Binary diagram](Decimal to Binary diagram) - **Technique** - Divide by two, keep track of the remainder - First remainder is bit 0 (LSB, least-significant bit) - Second remainder is bit 1 - Etc. - **Example** $125_{10} = ?_2$ ``` 2 | 125 2 | 62 1 2 | 31 0 2 | 15 1 2 | 7 1 2 | 3 1 2 | 1 1 ``` Therefore, $125_{10} = 1111101_2$ ## Decimal to Binary Conversion Convert (0.6875)10 to binary. | Integer | Fraction | |---------|----------| | 1 | 0.3750 | | 0 | 0.7500 | | 1 | 0.5000 | | 1 | 0.0000 | Answer: (0.6875)10 = (0.1011)2 (41.6875)10 = (101001.1011)2 ## Binary to Decimal ![Binary to Decimal diagram](Binary to Decimal diagram) - **Technique** - Multiply each bit by 2n, where n is the “weight” of the bit - The weight is the position of the bit, starting from 0 on the right - Add the results - **Example** Bit "0" $101011_2 =>$ ``` 1 x 2° = 1 1 x 2¹ = 2 0 x 2² = 0 1 x 2³ = 8 0 x 2⁴ = 0 1 x 2⁵ = 32 ``` Therefore, $101011_2 = 43_{10}$ ## Octal to Decimal ![Octal to Decimal diagram](Octal to Decimal diagram) - **Technique** - Multiply each bit by 8n, where n is the “weight” of the bit - The weight is the position of the bit, starting from 0 on the right - Add the results - **Example** $724_8 =>$ ``` 4 x 8⁰ = 4 2 x 8¹ = 16 7 x 8² = 448 ``` Therefore, $724_8 = 468_{10}$ ## Hexadecimal to Decimal ![Hexadecimal to Decimal diagram](Hexadecimal to Decimal diagram) - **Technique** - Multiply each bit by 16n, where n is the “weight” of the bit. - The weight is the position of the bit, starting from 0 on the right. - Add the results - **Example** $ABC_{16} =>$ ``` C x 16⁰ = 12 x 1 = 12 B x 16¹ = 11 x 16 = 176 A x 16² = 10 x 256 = 2560 ``` Therefore, $ABC_{16} = 2748_{10}$ ## Octal to Binary ![Octal to Binary diagram](Octal to Binary diagram) - **Technique** - Convert each octal digit to a 3-bit equivalent binary representation - **Example** $705_8 = ?_2$ ``` 7 0 5 ↓ ↓ ↓ 111 000 101 ``` Therefore, $705_8 = 111000101_2$ ## Hexadecimal to Binary ![Hexadecimal to Binary diagram](Hexadecimal to Binary diagram) - **Technique** - Convert each hexadecimal digit to a 4-bit equivalent binary representation. - **Example** $10AF_{16} = ?_2$ ``` 1 0 A F ↓ ↓ ↓ ↓ 0001 0000 1010 1111 ``` Therefore, $10AF_{16} = 0001000010101111_2$ ## Decimal to Octal ![Decimal to Octal diagram](Decimal to Octal diagram) - **Technique** - Divide by 8 - Keep track of the remainder - **Example** $1234_{10} = ?_8$ ``` 8 | 1234 8 | 154 2 8 | 19 2 8 | 2 3 ``` Therefore, $1234_{10} = 2322_8$ ## Decimal to Octal Conversion Convert (0.513)10 to octal. | | | |----------|----------| | 0.513 x 8 | 4.104 | | 0.104 x 8 | 0.832 | | 0.832 x 8 | 6.656 | | 0.656 x 8 | 5.248 | | 0.248 x 8 | 1.984 | | 0.984 x 8 | 7.872 | Answer: (0.513)10 = (0.406517... )8 (153.513)10 = (231.406517)8 ## Decimal to Hexadecimal ![Decimal to Hexadecimal diagram](Decimal to Hexadecimal diagram) - **Technique** - Divide by 16 - Keep track of the remainder - **Example** $1234_{10} = ?_{16}$ ``` 16 | 1234 16 | 77 2 16 | 4 13 = D ``` Therefore, $1234_{10} = 4D2_{16}$. ## Binary to Octal ![Binary to Octal diagram](Binary to Octal diagram) - **Technique** - Group bits in threes, starting on right - Convert to octal digits - **Example** $1011010111_2 = ?_8$ ``` 1 011 010 111 ↓ ↓ ↓ ↓ 1 3 2 7 ``` Therefore, $1011010111_2 = 1327_8$ ## Binary to Hexadecimal ![Binary to Hexadecimal diagram](Binary to Hexadecimal diagram) - **Technique** - Group bits in fours, starting on right - Convert to hexadecimal digits - **Example** $1010111011_2 = ?_{16}$ ``` 10 1011 1011 ↓ ↓ ↓ 2 B B ``` Therefore, $1010111011_2 = 2BB_{16}$ ## Octal to Hexadecimal ![Octal to Hexadecimal diagram](Octal to Hexadecimal diagram) - **Technique** - Use binary as an intermediary - **Example** $1076_8 = ?_{16}$ ``` 1 0 7 6 ↓ ↓ ↓ ↓ 001 000 111 110 ↓ ↓ ↓ ↓ 2 3 E ``` Therefore, $1076_8 = 23E_{16}$ ## Hexadecimal to Octal ![Hexadecimal to Octal diagram](Hexadecimal to Octal diagram) - **Technique** - Use binary as an intermediary - **Example** $1F0C_{16} = ?_8$ ``` 1 F 0 C ↓ ↓ ↓ ↓ 0001 1111 0000 1100 ↓ ↓ ↓ ↓ 1 7 4 14 ``` Therefore, $1F0C_{16} = 17414_8$ ## Exercise - Convert ... | Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 33 | | | | | | 1110101| | | | | | 703 | | | | | | 1AF | ## Exercise - Convert ... **Answer** | Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 33 | 100001 | 41 | 21 | | 117 | 1110101| 165 | 75 | | 451 | 111000011| 703 | 1C3 | | 431 | 110101111| 657 | 1AF | ## Common Powers (1 of 2) - **Base 10** | Power | Preface | Symbol | Value | |-------|---------|--------|---------------------------------| | 10⁻¹² | pico | p | .000000000001 | | 10⁻⁹ | nano | n | .000000001 | | 10⁻⁶ | micro | μ | .000001 | | 10⁻³ | milli | m | .001 | | 10³ | kilo | k | 1000 | | 10⁶ | mega | M | 1000000 | | 10⁹ | giga | G | 1000000000 | | 10¹² | tera | T | 1000000000000 | ## Common Powers (2 of 2) - **Base 2** | Power | Preface | Symbol | Value | |-------|---------|--------|---------------------------------| | 2¹⁰ | kilo | k | 1024 | | 2²⁰ | mega | M | 1048576 | | 2³⁰ | Giga | G | 1073741824 | - What is the value of “k”, “M”, and “G”? - In computing, particularly w.r.t. memory, the base-2 interpretation generally applies. ## Example ![Example Screenshot](Example Screenshot) This is a screenshot of a hard drive's properties, showing the used space. The example illustrates how to convert bytes to Gigabytes using the concept of Base 2 powers. ## Review - Multiplying Powers - For common bases, add powers $a^b * a^c = a^{b+c}$ $2^6 * 2^{10} = 2^{16} = 65,536$ or... $2^6 * 2^{10} = 64 * 2^{10}= 64k$ ## Binary Addition (1 of 2) - **Two 1-bit values** | A | B | A + B | |---|---|-------| | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 10 | "two" ## Binary Addition (2 of 2) - **Two n-bit values** - Add individual bits - Propagate carries - E.g., ``` 1 1 10101 + 11001 ----- 101110 ``` This is a binary addition example illustrating how to add two binary numbers. ## Multiplication (1 of 3) - **Decimal (just for fun)** ``` 35 x 105 ---- 175 000 35 ---- 3675 ``` This is a simple decimal multiplication to show how to multiply numbers in decimal representation. ## Multiplication (2 of 3) - **Binary, two 1-bit values** | A | B | A x B | |---|---|-------| | 0 | 0 | 0 | | 0 | 1 | 0 | | 1 | 0 | 0 | | 1 | 1 | 1 | ## Multiplication (3 of 3) - **Binary, two n-bit values** - As with decimal values -E.g., ``` 1110 x 1011 ----- 1110 1110 0000 1110 ----- 10011010 ``` This is a binary multiplication example showcasing how to multiply two binary numbers. ## Fractions - **Decimal to decimal (just for fun)** $3.14 => 4 * 10^{-2} = 0.04$ $1* 10^{-1} = 0.1$ $3 * 10^{0} = \frac{3}{3.14}$ - **Binary to decimal** $10.1011 => 1 * 2^{-4} = 0.0625$ $1 * 2^{-3} = 0.125$ $0 * 2^{-2} = 0.0$ $1 * 2^{-1} = 0.5$ $0 * 2^{0} = 0.0$ $1 * 2^{1} = 2.0$ Therefore, $10.1011 = 2.6875$ ## Decimal to binary $3.14579$ ``` x.14579 2 0.29158 2 0.58316 2 1.16632 2 0.33264 2 0.66528 2 1.33056 2 etc. ``` Therefore, $3.14579 = 11.001001...$ ## Exercise - Convert ... | Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 29.8 | | | | | | 101.1101| | | | | | 3.07 | | | | | | C.82 | ## Exercise - Convert ... **Answer** | Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 29.8 | 11101.110011... | 35.63... | 1D.CC... | | 5.8125 | 101.1101 | 5.64 | 5.D | | 3.109375| 11.000111 | 3.07 | 3.1C | | 12.5078125| 1100.10000010 | 14.404 | C.82 | ## Thanks for the tolerance <br> This document provides an overview of different number systems and their conversion methods. It also includes exercises for practicing those conversions. This should help you understand how numbers are represented and manipulated in different bases, which is essential for working with computers and digital systems.

Use Quizgecko on...
Browser
Browser