ITEC 1000 Introduction to Information Technology Lecture 2
























































































- Slides: 88
ITEC 1000 “Introduction to Information Technology” Lecture 2 Number Systems Decimal Octal Binary Hexadecimal 1
Lecture Template: Types of number systems n Number bases n Range of possible numbers n Conversion between number bases n Common powers n Arithmetic in different number bases n Shifting a number n 2
Types of Number Systems n Additive: n Positional: n Additive Number Systems Numbers have intrinsic value: e. g. : Roman Numerals: LVIII = 50 + 5 + 1 + 1 = 58 Value depends on position: e. g. : Decimal system: 54 = 5 x 10 + 4 x 1 are not used much any more: • Awkward to use. • Prone to errors. 3
Definitions n The Base of a number system – how many different digits (incl. zero) are used in the system. Base 2: Base 5: Base 8: Base 10: Base 16: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F 4
Definitions Bit – a cell holding a single binary number (0 or 1) n Byte = 8 bits (can hold 28 = 256 different patterns/values) n Word – a fixed-sized group of bits that the computer handles together. Typical word sizes: 4, 8, 16, 32, 64, 128 bits n 1 K = 1024 bytes n 5
Magnetic Core Memory http: //en. wikipedia. org/wiki/Computer 6
Common Number Systems System Decimal Used by humans ? Used in computers? 0, 1, … 9 Yes No Base Symbols 10 Binary 2 0, 1 No Yes Octal 8 0, 1, … 7 No Yes 16 0, 1, … 9, A, B, … F No Yes Hexadecimal 7
Positional decimal system The number 125 means: 1 group of 100 2 groups of 10 5 groups of 1 (100 = 102) (10 = 101) (1 = 100) 8
Place values (1 of 2) In our usual positional number system, the meaning of a digit depends on where it is located in the number Example: 3732 3 groups of 1000 7 groups of 100 3 groups of 10 2 groups of 1 9
Place values (2 of 2) Weight 12510 => 5 x 100 2 x 101 1 x 102 = 5 = 20 = 100 125 Base 10
Representing in bases: 10, 2, 8, 16 n n 86510 = 8 x 102 + 6 x 101 + 5 x 100 = 800 + 60 + 5 10112 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 8 + 2 + 1 = 1110 258 = 2 x 81 + 5 x 80 = 16 + 5 = 2110 A 716 = 10 x 161 + 7 x 160 = 160 + 7 = 16710 Base Note: The subscript naming the base is itself given in base ten (10), by convention. 11
Counting in bases (1 of 3) Decimal Binary Octal Hexadecimal 0 1 0 1 2 3 4 5 6 7 10 11 100 101 110 111 2 3 4 5 6 7 12
Counting in bases (2 of 3) Decimal Binary Octal Hexadecimal 8 9 1000 1001 10 11 8 9 10 11 12 13 14 15 1010 1011 1100 1101 1110 1111 12 13 14 15 16 17 A B C D E F 13
Counting in bases (3 of 3) Decimal Binary Octal Hexadecimal 16 17 10000 10001 20 21 10 11 18 19 20 21 22 23 10010 10011 10100 10101 10110 10111 22 23 24 25 26 27 12 13 14 15 16 17 14
Estimating magnitude: Binary 1101 01102 = 21410 1101 01102 > 19210 (128 + 64 + additional bits to the right) Place 27 26 25 24 23 22 21 20 Value 128 64 32 16 8 4 2 1 Evaluate 1 x 128 1 x 64 0 x 32 1 x 16 0 x 8 1 x 4 1 x 2 0 x 1 Sum for Base 10 128 64 0 16 0 4 2 0 15
Range of possible numbers n R = BK where R = range B = base K = number of digits n Example #1: Base 10, 2 digits R = 102 = 100 different numbers (0… 99) n Example #2: Base 2, 16 digits R = 216 = 65, 536 or 64 K 16 -bit PC can store 65, 536 different number values 16
Decimal Range for Bit Widths Bits Digits 1 0+ 4 1+ 8 2+ Range 2 (0 and 1) 16 (0 to 15) 256 10 3 1, 024 (1 K) 16 4+ 65, 536 (64 K) 20 6 1, 048, 576 (1 M) 32 9+ 64 19+ Approx. 1. 6 x 1019 128 38+ Approx. 2. 6 x 1038 4, 294, 967, 296 (4 G) See also Ch. 2, p. 33 17
Conversion Among Bases Decimal Octal Binary Hexadecimal 18
Binary to Decimal (1 of 3) Decimal Octal Binary Hexadecimal 19
Binary to Decimal (2 of 3) n Technique n n n Multiply each bit by 2 n, 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 20
Binary to Decimal (3 of 3) Bit “ 0” 1010112 => 1 1 0 1 x x x 20 21 22 23 24 25 = = = 1 2 0 8 0 32 4310 21
Octal to Decimal (1 of 3) Decimal Octal Binary Hexadecimal 22
Octal to Decimal (2 of 3) n Technique n n n Multiply each bit by 8 n, 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 together Note: 80 = 1, 82 = 64 81 = 8, 83 = 512, Etc. 23
Octal to Decimal (3 of 3) 7248 => 4 x 80 = 2 x 81 = 7 x 82 = 4 x 1 2 x 8 7 x 64 = 16 = 448 46810 24
Hexadecimal to Decimal (1 of 3) Decimal Octal Binary Hexadecimal 25
Hexadecimal to Decimal (2 of 3) n Technique n n n Multiply each bit by 16 n, 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 Note: 160 = 1, 161 = 16, 162 = 256 163 = 4096, Etc. 26
Hexadecimal to Decimal (3 of 3) ABC 16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560 274810 27
Decimal to Binary (1 of 3) Decimal Octal Binary Hexadecimal 28
Decimal to Binary (2 of 3) n Technique n n Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc. 29
Decimal to Binary (3 of 3) 12510 = ? 2 2 125 2 62 2 31 2 15 7 2 3 2 1 2 0 1 1 1 12510 = 11111012 30
Octal to Binary (1 of 3) Decimal Octal Binary Hexadecimal 31
Octal to Binary (2 of 3) n Technique • Convert each octal digit to a 3 -bit equivalent binary representation See Table, Slides 12 -14 32
Octal to Binary (3 of 3) 7058 = ? 2 7 0 5 111 000 101 7058 = 1110001012 33
Hexadecimal to Binary (1 of 3) Decimal Octal Binary Hexadecimal 34
Hexadecimal to Binary (2 of 3) n Technique n Convert each hexadecimal digit to a 4 -bit equivalent binary representation See Table, Slides 12 -14 35
Hexadecimal to Binary (3 of 3) 10 AF 16 = ? 2 1 0 A F 0001 0000 1010 1111 10 AF 16 = 000101011112 36
Decimal to Octal (1 of 3) Decimal Octal Binary Hexadecimal 37
Decimal to Octal (2 of 3) n Technique n n Divide by 8 Keep track of the remainder 38
Decimal to Octal (3 of 3) 123410 = ? 8 8 8 1234 154 19 2 0 2 2 3 2 123410 = 23228 39
Decimal to Hexadecimal (1 of 3) Decimal Octal Binary Hexadecimal 40
Decimal to Hexadecimal (2 of 3) n Technique n n Divide by 16 Keep track of the remainder 41
Decimal to Hexadecimal (3 of 3) 123410 = ? 16 16 1234 77 4 0 2 13 = D 4 123410 = 4 D 216 42
Binary to Octal (1 of 3) Decimal Octal Binary Hexadecimal 43
Binary to Octal (2 of 3) n Technique Group bits in threes, starting on right Convert to octal digits See Table, Slides 12 -14 44
Binary to Octal (3 of 3) 10110101112 = ? 8 1 010 111 1 3 2 7 10110101112 = 13278 45
Binary to Hexadecimal (1 of 3) Decimal Octal Binary Hexadecimal 46
Binary to Hexadecimal (2 of 3) n Technique n n Group bits in fours, starting on right Convert to hexadecimal digits See Table, Slides 12 -14 47
Binary to Hexadecimal (3 of 3) 1010112 = ? 16 10 1011 2 B B 1010112 = 2 BB 16 48
Octal to Hexadecimal (1 of 3) Decimal Octal Binary Hexadecimal 49
Octal to Hexadecimal (2 of 3) n Technique n Use binary as an intermediary See Table, Slides 12 -14 50
Octal to Hexadecimal (3 of 3) 10768 = ? 16 1 0 7 6 001 000 111 110 2 3 E 10768 = 23 E 16 51
Hexadecimal to Octal (1 of 3) Decimal Octal Binary Hexadecimal 52
Hexadecimal to Octal (2 of 3) n Technique Use binary as an intermediary See Table, Slides 12 -14 53
Hexadecimal to Octal (3 of 3) 1 F 0 C 16 = ? 8 1 0001 1 F 0 1111 7 C 0000 4 1100 1 4 1 F 0 C 16 = 174148 54
Exercise – Convert. . . Decimal 33 Binary Octal Hexadecimal 1110101 703 1 AF Don’t use a calculator! Skip answer Answer 55
Exercise – Convert (answers) Decimal 33 117 Binary 100001 1110101 Octal 41 165 451 431 111000011 110101111 703 657 Hexadecimal 21 75 1 C 3 1 AF 56
Common Powers (1 of 2) n Base 10 Power Preface Symbol Value 10 -12 pico p . 0000001 10 -9 nano n . 00001 10 -6 micro . 000001 10 -3 milli m . 001 103 kilo k 1000 106 mega M 1000000 109 giga G 100000 1012 tera T 1000000 57
Common Powers (2 of 2) n Base 2 Power Preface Symbol Value 210 kilo k 1024 220 mega M 1048576 230 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 58
Example 1. Double click on My Computer 2. Right click on C: 3. Click on Properties / 230 = 59
Multiplying powers n For common bases, add powers ab ac = ab+c 26 210 = 216 = 65, 536 or… 26 210 = 64 k 60
Table of powers Pow er 8 7 6 5 4 3 2 1 0 128 64 32 16 8 4 2 1 32, 76 8 4, 096 512 64 8 1 65, 53 6 4, 09 6 256 16 1 Base 2 8 16 256 61
Fractions n Number point or radix point Decimal point in base 10 n Binary point in base 2 n n No exact relationship between fractional numbers in different number bases n Exact conversion may be impossible 62
Decimal fractions n Move the number point one place to the right Effect: multiplies the number by the base number Example: 139. 010 139010 n Move the number point one place to the left Effect: divides the number by the base number Example: 139. 010 13. 910 63
Fractions: Base 10 10 -1 10 -2 10 -3 10 -4 . 258910 Place 10 -1 10 -2 10 -3 10 -4 Value 1/10000 2 x 1/10 5 x 1/100 8 x 1/1000 9 x 1/10000 . 2 . 05 . 008 . 0009 Evaluate Sum 64
Fractions: Base 2 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 . 1010112 = 0. 67187510 Place 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 Value 1/2 1/4 1/8 1/16 1/32 1/64 1 x 1/2 0 x 1/4 1 x 1/8 0 x 1/16 1 x 1/32 1 x 1/64 0. 03125 0. 015625 Evaluate Sum . 5 0. 125 65
Fractions: Base 10 and Base 2 n No general relationship between fractions of types 1/10 k and 1/2 k Therefore a number representable in base 10 may not be representable in base 2 But: the converse is true: all fractions of the form 1/2 k can be represented in base 10 n Fractional conversions from one base to another are stopped If there is a rational solution, or When the desired accuracy is attained 66
Fractions: From Base B To Base 10 n n Determine the appropriate weight for each fractional digit as a negative power of the base Multiply each digit by its weight Add the values Example: n . A 116 = 10 x 16 -1 + 1 x 16 -2 = 10 x 0. 0625 + 1 x 0. 00390625 = 0. 6289062510 67
Fractions: From Base 10 To Base B Multiply the fraction by the base value B (i. e. , 2, 8 or 16) n Record the values that move to the left of the radix point and drop them n Repeat the process until n the value being multiplied is zero, or n the desired number of digits of accuracy is attained n 68
Fractions: From Base 10 To Base B 0. 67312510 = ? 2 0. 1010112 0. 673125 x 2 1. 346250 x 2 0. 692500 x 2 1. 385000 x 2 0. 770000 x 2 1. 540000 x 2 1. 080000 69
Fractions: From Base 2 To Base 8, 16 Group digits from left to right in groups of 3 (base 8) or 4 (base 16) n Supplement the right-most group with 0’s, if necessary n Convert each group to the desired base. n See Table, Slides 12 -14 70
Fractions: From Base 8, 16 To Base 2 n Convert each octal (base 8) or hexadecimal (base 16) digit to its 3 bit or 4 -bit representation See Table, Slides 12 -14 71
Fractions: between Base 8 and Base 16 Use binary conversion as an intermediary n Example: 0. C 816 = ? 8 n 1100 10002 6 2 0 0. C 816 = 0. 628 72
Mixed number conversion n Convert whole part and fraction part separately See Table, Slides 12 -14 73
Arithmetic operations (1 of 14) n Binary Addition n Two 1 -bit values A 0 0 1 1 B 0 1 A+B 0 1 1 10 0 and carry 1 to the next more significant bit, i. e. 74 “two”
Arithmetic operations (2 of 14) n Two n-bit values n n Add individual bits (see Table) Propagate carries 1 1 10101 + 11001 101110 21 + 25 46 Note: superscripts are carried amounts. 75
Addition (different bases) (3 of 14) Base Problem Largest Single Digit Decimal 6 +3 9 Octal 6 +1 7 Hexadecimal 6 +9 F Binary 1 +0 1 76
Addition (different bases) (4 of 14) Base Problem Carry Answer Decimal 6 +4 Carry the 10 10 Octal 6 +2 Carry the 8 10 Hexadecimal 6 +A Carry the 16 10 Binary 1 +1 Carry the 2 10 77
Addition Table: Base 10 (5 of 14) 310 + 610 = 910 + 0 1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 10 2 2 3 4 5 6 7 8 9 10 11 3 3 4 5 6 7 8 9 10 11 12 4 4 5 6 7 8 9 10 11 12 13 etc 78
Addition Table: Base 8 (6 of 14) 38 + 68 = 118 + 0 1 2 3 4 5 6 7 0 0 1 2 3 4 5 6 7 10 2 2 3 4 5 6 7 10 11 3 3 4 5 6 7 10 11 12 4 4 5 6 7 10 11 12 13 5 5 6 7 10 11 12 13 14 6 6 7 10 11 12 13 14 15 7 7 10 11 12 13 14 15 16 79
Arithmetic operations (7 of 14) n Binary Subtraction n Two 1 -bit values A 0 0 1 1 B 0 1 A-B 0 1 1 0 and borrow 1 from the next more significant bit 80
Arithmetic operations (8 of 14) n Two n-bit values Subtract individual bits (see Table) n Keep track of the borrowings 00100101 – 0001 = 00010100 n 0 10 00100101 - 00010100 3710 - 1710 2010 81
Arithmetic operations (9 of 14) n Multiplication n Decimal (just for fun) 35 x 105 175 000 35 3675 82
Arithmetic operations (10 of 14) n Binary multiplication, two 1 -bit values A B 0 0 1 1 1 83
Arithmetic operations (11 of 14) n Binary multiplication, two n-bit values n As with decimal values 1110 x 1011 1110 0000 1110 10011010 84
Multiplication Table: Base 10 (12 of 14) 310 x 610 = 1810 x 0 1 2 0 3 4 5 6 7 8 9 0 1 1 2 3 4 5 6 7 8 9 2 2 4 6 8 10 12 14 16 18 3 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 5 10 15 20 25 30 35 40 45 6 6 12 18 24 30 36 42 48 54 7 7 14 21 28 35 42 49 56 63 4 0 etc. 85
Multiplication Table: Base 8 (13 of 14) 38 x 68 = 228 x 0 1 2 0 3 4 5 6 7 0 1 1 2 3 4 5 6 7 2 2 4 6 10 12 14 16 3 6 11 14 17 22 25 4 4 10 14 20 24 30 34 5 5 12 17 24 31 36 43 6 6 14 22 30 36 44 52 7 7 16 25 34 43 52 61 3 0 86
Arithmetic operations (14 of 14) n Binary division, two n-bit values n As with decimal values 100001/11 = 1011 quotient 1011 11 ) 100001 11 divisor 00100 11 dividend 11 11 0 87
Shifting a number n n n Shifting a decimal number to the left by one position is equivalent to multiplying by 10 Shifting a binary number to the left by one position is equivalent to multiplying by 2 General rule: shifting a number in any base left one digit multiplies its value by the base; shifting one digit right divides its value by the base 88
























































































