Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary & Hex Review.

Similar presentations


Presentation on theme: "Binary & Hex Review."— Presentation transcript:

1 Binary & Hex Review

2 Bits & Bytes

3 Bits And Bit Patterns N bits gives 2N possible patterns
2 bits = 4 patterns 3 bits = 8 patterns

4 Bytes Smallest usable chunk of memory: byte : 8 bits
Special names for large collections of bytes: Name Number of Bytes power of 2 byte 1 20 kilobyte (KB) 1024 210 megabyte (MB) 1,048,576 220 gigabyte (GB) 1,073,741,824 230 terabyte (TB) 1,099,511,627,776 240

5 Metric Units Standard metric units

6 Explaining Size What the hell MS?

7 Bi units Metric prefixes May refer to powers of 2 or 10
Roughly equivalent GB GiB 109 = ~ = 230

8 Bi units Memory measured in powers of 2
Network / Processor in powers of 10 Disk manufactures powers of 10 OS powers of 2 2 TB = 2 * * 1012 / 240 = GiB

9 Unsigned Binary

10 Bases Place based number representations: 1 2 5 9 1 ten thousands 104
103 hundreds 102 tens 101 ones 100 1 2 5 9 thirty-twos 25 sixteens 24 eights 23 fours 22 twos 21 ones 20 1

11 Specifying Base Specify base as subscript: 610 = 1102

12 Binary Number Interpretation
Table Method: = = 10510 128 64 32 16 8 4 2 1

13 Leading 0's Leading 0's do not matter: 101 = 0101 = 00000101
Byte : fundamental storage unit : 8 bits Often write binary numbers in multiples 8 bits 128 64 32 16 8 4 2 1

14 Conversion With Division/ Multiplication
Binary works in powers of 2 Multiplying/dividing by 2 shifts digits

15 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105

16 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1

17 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1

18 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2

19 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01

20 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01 26 ÷ 2 13 001

21 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01 26 ÷ 2 13 001 13 ÷ 2 6 1001 6 ÷ 2 3 01001 3 ÷ 2 101001 1 ÷ 2

22 Decimal -> Binary with Division
Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01 26 ÷ 2 13 001 13 ÷ 2 6 1001 6 ÷ 2 3 01001 3 ÷ 2 101001 1 ÷ 2 128 64 32 16 8 4 2 1 = 105

23 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101

24 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 0 * 2

25 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 0 * 2 + 1

26 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1

27 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 1 * 2

28 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 1 * 2 + 1

29 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3

30 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 3 * 2

31 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 3 * 2 + 0

32 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 6

33 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 6 6 * 2

34 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 6 _ 6 * 2 + 1

35 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 6 _ 13

36 Binary -> Decimal with Multiplication
Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert to decimal:  Number Answer 1101 101 1 01 3 6 _ 13 128 64 32 16 8 4 2 1 = 13

37 Unsigned Binary Math

38 Adding Adding base 2: 1 1 = 1 2 = 10 = keep 0 and carry 1
1 = 1 2 = 10 = keep 0 and carry 1 3 = 11 = keep 1 carry 1 1

39 Adding Adding base 2: 1 7 5 12 1 = 1 2 = 10 = keep 0 and carry 1
1 = 1 2 = 10 = keep 0 and carry 1 3 = 11 = keep 1 carry 1 7 5 12 1

40 Overflow What is ? 1

41 Overflow What is ? Overflow: number gets too big to hold in the digits we have 1

42 Signed Binary

43 Sign Magnitude?? - / + are two choices Ex: + 5 - 5 sign 4 2 1 sign 4 2
Use a bit value to represent sign Ex: + 5 - 5 sign 4 2 1 sign 4 2 1

44 Sign Magnitude?? Would need new math algorithm… 1 -3 1

45 2’s complement 2's Complement System: First bit indicates sign:
0 : Positive #: works like normal What is: 00110 Bit Values: 4+2 Value: 6

46 2’s complement 2's Complement System: First bit indicates sign:
1 : Negative #: defined as indicated value – 2n where n is number of bits What is: 11010 Bit Values: = 26 2n : 25 = 32 Value: 26 – 32 = -6

47 2’s complement negation
To negate a number, reverse bits and add 1 What is -3 as 4-bit 2's complement number?: 0011 start with reverse in two's complement Check: = = 13 2n = 24 = 16 13 – 16 = -3

48 2’s complement negation
To negate a number, reverse bits and add 1 What is 1101 as a 4-bit 2’s complement number? 1101 start with negative pattern reverse interpret add one negated is 3, so it must be -3

49 More Examples What are? 1 1 1

50 More Examples What are? 1 1 1 Starts with 0 = normal:

51 More Examples What are? 4 + 2 + 1 7 1 -1 1 1 1 1
1 1 1 Starts with 0 = normal: Starts with 1 = negative: Flip Bits Add one: Read number, make negative: 1 -1 1

52 More Examples What are? 4 + 2 + 1 7 1 -1 8 -8 1 1 1 1 1 1
1 1 1 Starts with 0 = normal: Starts with 1 = negative: Flip Bits Add one: Read number, make negative: 1 -1 Starts with 1 = negative: Flip Bits Add one: Read number, make negative: 1 1 1

53 Range 2's complement uses half of range for negative, half for 0/positive 4 bits: 24 = 16 values Unsigned 0 to 15 2's Complement -8 to 7

54 4 bits Biggest positive: 7 -1 : Lowest negative: -8 1 1 Flip (0)
1 1 Flip (0) +1 = 1 1 Flip (7) +1 = 8

55 8 bits Biggest positive: 127 -1 : Lowest negative: -128 1 1 Flip (0)
1 1 Flip (0) +1 = 1 1 Flip (127) +1 = 128

56 2’s complement addition
Standard addition algorithm works fine: : 1 -3 1

57 2’s complement addition
Standard addition algorithm works fine: : 1 -3 -2 1 ??? 110 Reverse Bits 001 Interpret 1 Add One 2 Value -2

58 2’s complement 2 + 4 = 1

59 2’s complement 2 + 4 = 6 Success – answer fits in four bits Ignore extra carry 1

60 2’s complement -3 + -2 = 1 3 0011 Reverse Bits 1100 Add one 1101 2
0010 Reverse Bits 1101 Add one 1110 = 1

61 2’s complement ??? 1011 Reverse Bits 0100 Add one 0101 Bit Values 1 + 4 Value -5 = -5 Success – answer fits in four bits Ignore extra carry 1

62 2’s complement = 1

63 2’s complement 4 + 6 = -6!?!?! Overflowed the 4 bits! 1 ??? 1010
Reverse Bits 0101 Add one 0110 Bit Values 2 + 4 Value -6 = -6!?!?! Overflowed the 4 bits! 1

64 2’s complement -4 + -6 = 1 4 0100 Reverse Bits 1011 Add one 1100 6
0110 Reverse Bits 1001 Add one 1010 1

65 2’s complement = 6??? Overflowed the 4 bits! 1

66 Overflow Big + numbers and Low – numbers can wrap!

67 Hexadecimal

68 Hexdecimal Base 16 Each column is a power of 16:
= 4096 * * * * 9 = = 4096’s 163 256’s 162 16’s 161 1’s 160 2 5 9

69 13? How do we represent 13??? 4096’s 163 256’s 162 16’s 161 1’s 160

70 13? How do we represent 13??? A-F = 10-15 4096’s 256’s 16’s 1’s 163
162 16’s 161 1’s 160

71 Hex Numbers 1A316 = 1 * 256 + 10 * 16 + 3 * 1 = 256 + 160 + 3 = 41910
4096 256 16 1 A 3

72 Decimal   Hex Division Methods: ÷ 16 7 12 (C) C7 1C7 Current Value
Quotient Remainder 455 ÷ 16 28 7 1 12 (C) C7 1C7

73 Hex Hexdecimal = base 16 4 bits = 1 hex digit

74 Summary Hex is a bridge: Easier for us Still just binary for computers
System Base Symbols Used by humans? Used in computers? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 Hex 16 0-9ABCDEF No, but better than binary No, but easily translates to binary


Download ppt "Binary & Hex Review."

Similar presentations


Ads by Google