Download presentation
Presentation is loading. Please wait.
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 2TB Drive:
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
This Class Unless stated otherwise, assume all measurements are powers of 2
10
Powers of 2 How many bytes is 16GB?
11
Powers of 2 How many bytes is 16GB? = 16 * 230 = 24 * 230 = 234
12
Unsigned Binary
13
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
14
Specifying Base Specify base as subscript: 610 = 1102
15
Binary Number Interpretation
Table Method: = = 10510 128 64 32 16 8 4 2 1
16
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
17
Conversion With Division/ Multiplication
Binary works in powers of 2 Multiplying/dividing by 2 shifts digits
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
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
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
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
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
23
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
24
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
25
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
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
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 0 * 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 0 * 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
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 1 * 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 1 * 2 + 1
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
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 3 * 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 3 * 2 + 0
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
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 6 * 2
37
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
38
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
39
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
40
Unsigned Binary Math
41
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
42
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
43
Overflow What is ? 1
44
Overflow What is ? Overflow: number gets too big to hold in the digits we have 1
45
Signed Binary
46
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
47
Sign Magnitude?? Would need new math algorithm… 1 -3 1
48
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
49
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
50
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
51
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
52
More Examples What are? 1 1 1
53
More Examples What are? 1 1 1 Starts with 0 = normal:
54
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
55
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
56
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
57
4 bits Biggest positive: 7 -1 : Lowest negative: -8 1 1 Flip (0) 1
1 1 Flip (0) +1 = 1 1 Flip (7) +1 = 8
58
8 bits Biggest positive: 127 -1 : Lowest negative: -128 1 1 Flip (0) 1
1 1 Flip (0) +1 = 1 1 Flip (127) +1 = 128
59
2’s complement addition
Standard addition algorithm works fine: : 1 -3 1
60
2’s complement addition
Standard addition algorithm works fine: : 1 -3 -2 1 ??? 110 Reverse Bits 001 Interpret 1 Add One 2 Value -2
61
2’s complement 2 + 4 = 1
62
2’s complement 2 + 4 = 6 Success – answer fits in four bits Ignore extra carry 1
63
2’s complement -3 + -2 = 1 3 0011 Reverse Bits 1100 Add one 1101 2
0010 Reverse Bits 1101 Add one 1110 = 1
64
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
65
2’s complement = 1
66
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
67
2’s complement -4 + -6 = 1 4 0100 Reverse Bits 1011 Add one 1100 6
0110 Reverse Bits 1001 Add one 1010 1
68
2’s complement = 6??? Overflowed the 4 bits! 1
69
Overflow Big + numbers and Low – numbers can wrap!
70
2’s complement Final column carry out and in are == : OK
Final column carry out and in are != : Overflow 1
71
Hexadecimal
72
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
73
13? How do we represent 13??? 4096’s 163 256’s 162 16’s 161 1’s 160
74
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
75
Hex Numbers 1A316 = 1 * 256 + 10 * 16 + 3 * 1 = 256 + 160 + 3 = 41910
4096 256 16 1 A 3
76
Decimal Hex Division Methods: ÷ 16 7 12 (C) C7 1C7 Current Value
Quotient Remainder 455 ÷ 16 28 7 1 12 (C) C7 1C7
77
Hex Hexdecimal = base 16 4 bits = 1 hex digit
78
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.