Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Week 2: Binary, Octal and Hexadecimal Numbers READING: Chapter 2.

Similar presentations


Presentation on theme: "1 Week 2: Binary, Octal and Hexadecimal Numbers READING: Chapter 2."— Presentation transcript:

1 1 Week 2: Binary, Octal and Hexadecimal Numbers READING: Chapter 2

2 2 2 Positional Notation: Base Quick Re-cap: 1. Conversion from other bases to base 10, where b is the base of the original number, d i is the digit at the i-th position : 2. Conversion from base 10 to other bases EECS 1520 -- Computer Use: Fundamentals d n-1 * b n-1 + … + d 2 * b 2 + d 1 * b 1 + d 0 * b 0 Step 1: Always divide the decimal number by the new base, write down the quotient and the reminder Step 2: Divide the quotient by the new base, write down the new quotient and the new reminder Step 3: Repeat step 2 until the quotient is 0

3 3 3 Positional Notation: Base In general, we can convert numbers in any bases with the following method: EECS 1520 -- Computer Use: Fundamentals (number) A (number) 10 (number) B where A ≠ B ≠ 10

4 4 4 Positional Notation: Adding binary numbers Basic idea in adding digits in decimal: 1 + 2 = 3, 4 + 1 = 5…. EECS 1520 -- Computer Use: Fundamentals When you try to add two numbers whose sum is equal to or greater than the base value (i.e. 10), we reuse the same digits and rely on position. The rules of adding binary numbers are similar, but we run out of digits much faster (since we only have 2 digits) 0 + 1 1 + 0 1 0 + 0 0 1 + 1 1 0 9 + 1 1 0 1 is carried into the next position to the left 1 is called the “carry bit”

5 5 5 Positional Notation: Adding binary numbers Example 1: what is the sum of the following two binary numbers? EECS 1520 -- Computer Use: Fundamentals We can confirm that the above sum is correct by converting each of the above binary numbers to their decimal representations 0011 + 1001 1100

6 6 6 Positional Notation: Adding binary numbers EECS 1520 -- Computer Use: Fundamentals 0011 1001 convert to base 10 1*2 1 + 1*2 0 = 3 1100 convert to base 10 1*2 3 + 1*2 0 = 9 1*2 3 + 1*2 2 = 12

7 7 7 Positional Notation: Adding binary numbers Example 2: what is the sum of the following two binary numbers? EECS 1520 -- Computer Use: Fundamentals 0111 + 1101 10100 0111 1101 convert to base 10 1*2 2 + 1*2 1 + 1*2 0 = 4+2+1 = 7 10100 convert to base 10 1*2 3 + 1*2 2 + 1*2 0 = 8+4+1 = 13 1*2 4 + 1*2 2 = 16+4 = 20

8 8 8 Positional Notation: Power-of-2 number systems EECS 1520 -- Computer Use: Fundamentals Decimal (base 10)Binary (base 2)Octal (base 8) 000000 100011 200102 300113 401004 501015 601106 701117 8100010 9100111 10101012

9 9 9 Positional Notation: Power-of-2 number systems An unique relationship between binary and octal numbers, as 8 is a power of 2 (i.e. 8 = 2 3 ) Given an octal number, you can convert it directly to binary by replacing each digit in the octal number with the binary representation of that digit (note: the largest digit can only be “7”) EECS 1520 -- Computer Use: Fundamentals DecimalBinaryOctal 00000 10011 20102 30113 41004 51015 61106 71117

10 10 Positional Notation: Power-of-2 number systems EECS 1520 -- Computer Use: Fundamentals Example: what is the binary representation of the octal “154” ? 1 5 4 100 101001binary octal

11 11 Positional Notation: Power-of-2 number systems Now, if we convert the binary number to base 10: EECS 1520 -- Computer Use: Fundamentals We got 108, same as the number we got when we converted the octal number “154” to its base 10 representation: d n-1 * b n-1 + … + d 2 * b 2 + d 1 * b 1 + d 0 * b 0 1 * 8 2 + 5 * 8 1 + 4 * 8 0 = 64 + 40 + 4 = 108 001 101 100 1 * 2 6 + 1 * 2 5 + 1* 2 3 + 1 * 2 2 = 64 + 32 + 8 + 4 = 64 + 44 = 108

12 12 Positional Notation: Power-of-2 number systems Convert from binary number to octal number: EECS 1520 -- Computer Use: Fundamentals Step 1: start at the rightmost binary digit and mark the digits in groups of threes Step 2: convert each group of three into its octal value Note: Add 0s to the front if the leftmost group does not have 3 binary digits Example: what is the octal representation of the binary number: 1101111110 ? Note: any digits > 7 do not exist in octal, if you get an octal value > 7, something is wrong. 001 101 111 110 1 5 7 6 binary octal

13 13 Positional Notation: Power-of-2 number systems 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Recall that, in base-16, we have: EECS 1520 -- Computer Use: Fundamentals The previous “grouping” method can be applied to convert a binary number to its hexadecimal number (since 16 = 2 4 ) 0000, ……………………………………….., 1111binary hexadecimal

14 14 Positional Notation: Power-of-2 number systems Convert from binary number to hexadecimal number: EECS 1520 -- Computer Use: Fundamentals Step 1: start at the rightmost binary digit and mark the digits in groups of fours Step 2: convert each group of four into its hexadecimal value Note: Add 0s to the front if the leftmost group does not have 4 binary digits Example: what is the octal representation of the binary number: 1101111110 ? 0011 0111 1110 3 7 E binary hexadecimal

15 15 Positional Notation: Power-of-2 number systems Conversion between octal and hexadecimal numbers are much easier now as we can utilize the intermediate binary digits “grouping” method EECS 1520 -- Computer Use: Fundamentals Example: what is the hexadecimal representation of the octal number: 4567 ? 100 101 110 111 4 5 6 7octal binary 1001 0111 0111 hexadecimal 9 7 7

16 16 Positional Notation: Adding octal numbers EECS 1520 -- Computer Use: Fundamentals When you try to add two numbers whose sum is equal to or greater than the base value (i.e. 8), we reuse the same digits and rely on position. (7) 8 + (1) 8 (1 0) 8 1 is carried into the next position to the left Example 1: what is the sum of the following two octal numbers? (27) 8 + (35) 8 (64) 8

17 17 Positional Notation: Adding octal numbers EECS 1520 -- Computer Use: Fundamentals (27) 8 (35) 8 convert to base 10 2*8 1 + 7*8 0 = 16+7 = 23 (64) 8 convert to base 10 3*8 1 + 5*8 0 = 24+5 = 29 6*8 1 + 4*8 0 = 48+4 = 52

18 18 Positional Notation: Adding hexadecimal numbers EECS 1520 -- Computer Use: Fundamentals Same concept is applied to adding two hexadecimal numbers. When you try to add two hex numbers whose sum is equal to or greater than the base value (i.e. 16), we reuse the same digits and rely on position. (F) 16 + (1) 16 (1 0) 16 1 is carried into the next position to the left (F) 16 + (2) 16 (1 1) 16 (F) 16 + (3) 16 (1 2) 16 (F) 16 + (4) 16 (1 3) 16 and so on…..

19 19 Positional Notation: Adding hexadecimal numbers EECS 1520 -- Computer Use: Fundamentals Example: (2F) 16 + (73) 16 (A2) 16 (2F) 16 (73) 16 convert to base 10 2*16 1 + 15*16 0 = 32+15 = 47 (A2) 16 convert to base 10 7*16 1 + 3*16 0 = 112+3 = 115 10*16 1 + 2*16 0 = 160+2 = 162

20 20 Positional Notation: Subtracting two base 10 numbers EECS 1520 -- Computer Use: Fundamentals When you try to subtract a larger digit from a smaller one, we have to “borrow one” from the next left digit of the number from which you are subtracting. More precisely, we borrow one power of the base, such as in base 10, we borrow 10. 52 - 38 1 4 Borrow “10” from 5, so we have 10- 8 + 2 = 4 Example:

21 21 Positional Notation: Subtracting two binary numbers EECS 1520 -- Computer Use: Fundamentals In base 2, when borrow one power of the base to do subtraction, we borrow 2. In fact, we only need to borrow a 2 when we subtract 0 from 1. 1101 - 0110 Example: 0111 (1101) 2 (0110) 2 convert to base 10 13 (0111) 2 convert to base 10 6 7

22 22 Positional Notation: Subtracting two octal numbers EECS 1520 -- Computer Use: Fundamentals In base 8, when borrow one power of the base to do subtraction, we borrow 8. (153) 8 - (67) 8 Example: (64) 8 (153) 8 (67) 8 convert to base 10 107 (64) 8 convert to base 10 55 52

23 23 Positional Notation: Subtracting two hex numbers EECS 1520 -- Computer Use: Fundamentals In base 16, when borrow one power of the base to do subtraction, we borrow 16. (153) 16 - (67) 16 Example: (EC) 16 (153) 16 (67) 16 convert to base 10 339 (EC) 16 convert to base 10 103 236


Download ppt "1 Week 2: Binary, Octal and Hexadecimal Numbers READING: Chapter 2."

Similar presentations


Ads by Google