Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2 Number Systems

Similar presentations


Presentation on theme: "Lecture 2 Number Systems"— Presentation transcript:

1 Lecture 2 Number Systems
ITEC 1000 “Introduction to Information Technology” Lecture 2 Number Systems Hexadecimal Decimal Octal Binary Prof. Peter Khaiter

2 Lecture Template: Types of number systems Number bases
Range of possible numbers Conversion between number bases Common powers Arithmetic in different number bases Shifting a number

3 Types of Number Systems
Additive: Numbers have intrinsic value: e.g.: Roman Numerals: LVIII = = 58 Positional: Value depends on position: e.g.: Decimal system: 55 = 5 x x 1 Additive Number Systems are not used much any more: Awkward to use. Prone to errors.

4 Definitions The Base of a number system – how many different digits (incl. zero) are used in the system. Base 2: 0, 1 Base 5: 0, 1, 2, 3, 4 Base 8: 0, 1, 2, 3, 4, 5, 6, 7 Base 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Base 16: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

5 Definitions Bit – a cell holding a single binary number (0 or 1) Byte = 8 bits (can hold 28 = 256 different patterns/values) Word – a fixed-sized group of bits that the computer handles together. Typical word sizes: 4, 8, 16, 32, 64, 128 bits 1K = 1024 bytes

6 Magnetic Core Memory

7 Common Number Systems System Base Symbols Used by humans?
Used in computers? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 Octal 8 0, 1, … 7 Hexa- decimal 16 0, 1, … 9, A, B, … F

8 Positional decimal system
The number 125 means: 1 group of (100 = 102) 2 groups of (10 = 101) 5 groups of (1 = 100)

9 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: 3 groups of 1000 7 groups of 100 3 groups of 10 2 groups of 1

10 Place values (2 of 2) Weight
12510 => 5 x 100 = x 101 = x 102 = Base

11 Representing in bases: 10, 2, 8, 16
86510 = 8 x x x 100 = 10112 = 1 x x x x 20 = = 1110 258 = 2 x x 80 = = 2110 A716 = 10 x x 160 = = 16710 Note: The subscript naming the base is itself given in base ten (10), by convention. Base

12 Counting in bases (1 of 3) Decimal Binary Octal Hexa- decimal 1 2 10 3
1 2 10 3 11 4 100 5 101 6 110 7 111

13 Counting in bases (2 of 3) Decimal Binary Octal Hexa- decimal 8 1000
9 1001 11 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F

14 Counting in bases (3 of 3) Decimal Binary Octal Hexa- decimal 16 10000
20 10 17 10001 21 11 18 10010 22 12 19 10011 23 13 10100 24 14 10101 25 15 10110 26 10111 27

15 Estimating magnitude: Binary
= 21410 > ( 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 x16 0 x 8 1 x 4 1 x 2 0 x 1 Sum for Base 10

16 Range of possible numbers
R = BK where R = range B = base K = number of digits Example #1: Base 10, 2 digits R = 102 = 100 different numbers (0…99) Example #2: Base 2, 16 digits R = 216 = 65,536 or 64K 16-bit PC can store 65,536 different number values

17 Decimal Range for Bit Widths
Bits Digits Range 1 0+ 2 (0 and 1) 4 1+ 16 (0 to 15) 8 2+ 256 10 3 1,024 (1K) 16 4+ 65,536 (64K) 20 6 1,048,576 (1M) 32 9+ 4,294,967,296 (4G) 64 19+ Approx. 1.6 x 1019 128 38+ Approx. 2.6 x 1038 See also Ch. 3, p. 74

18 Conversion Among Bases
Hexadecimal Decimal Octal Binary

19 Binary to Decimal (1 of 3) Hexadecimal Decimal Octal Binary

20 Binary to Decimal (2 of 3) 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

21 Binary to Decimal (3 of 3) Bit “0”
=> 1 x 20 = x 21 = x 22 = x 23 = x 24 = x 25 = 32 4310 Bit “0”

22 Octal to Decimal (1 of 3) Decimal Octal Binary Hexadecimal

23 Octal to Decimal (2 of 3) Technique Note: 80 = 1, 81 = 8,
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 together Note: 80 = 1, 81 = 8, 82 = = 512, Etc.

24 Octal to Decimal (3 of 3) 7248 => 4 x 80 = 4 x 1 = x 81 = 2 x 8 = x 82 = 7 x 64 =

25 Hexadecimal to Decimal (1 of 3)
Octal Binary Hexadecimal

26 Hexadecimal to Decimal (2 of 3)
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 Note: 160 = 1, 161 = 16, 162 = = 4096, Etc.

27 Hexadecimal to Decimal (3 of 3)
ABC16 => C x 160 = 12 x 1 = B x 161 = 11 x 16 = A x 162 = 10 x 256 = 2560 274810

28 Decimal to Binary (1 of 3) Decimal Octal Binary Hexadecimal

29 Decimal to Binary (2 of 3) Technique
Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.

30 Decimal to Binary (3 of 3) 12510 = ?2 2 125 62 1 2 31 0 2 15 1 2 7 1
12510 =

31 Octal to Binary (1 of 3) Decimal Octal Binary Hexadecimal

32 Octal to Binary (2 of 3) Technique
Convert each octal digit to a 3-bit equivalent binary representation See Table, Slides 12-14

33 Octal to Binary (3 of 3) 7058 = ?2 7058 =

34 Hexadecimal to Binary (1 of 3)
Octal Binary Hexadecimal

35 Hexadecimal to Binary (2 of 3)
Technique Convert each hexadecimal digit to a 4-bit equivalent binary representation See Table, Slides 12-14

36 Hexadecimal to Binary (3 of 3)
10AF16 = ?2 A F 10AF16 =

37 Decimal to Octal (1 of 3) Decimal Octal Binary Hexadecimal

38 Decimal to Octal (2 of 3) Technique Divide by 8
Keep track of the remainder

39 Decimal to Octal (3 of 3) = ?8 8 19 2 8 2 3 8 0 2 = 23228

40 Decimal to Hexadecimal (1 of 3)
Octal Binary Hexadecimal

41 Decimal to Hexadecimal (2 of 3)
Technique Divide by 16 Keep track of the remainder

42 Decimal to Hexadecimal (3 of 3)
= ?16 77 2 16 = D 0 4 = 4D216

43 Binary to Octal (1 of 3) Decimal Octal Binary Hexadecimal

44 Binary to Octal (2 of 3) Technique
Group bits in threes, starting on right Convert to octal digits See Table, Slides 12-14

45 Binary to Octal (3 of 3) = ?8 = 13278

46 Binary to Hexadecimal (1 of 3)
Octal Binary Hexadecimal

47 Binary to Hexadecimal (2 of 3)
Technique Group bits in fours, starting on right Convert to hexadecimal digits See Table, Slides 12-14

48 Binary to Hexadecimal (3 of 3)
= ?16 2 B B = 2BB16

49 Octal to Hexadecimal (1 of 3)
Binary Hexadecimal

50 Octal to Hexadecimal (2 of 3)
Technique Use binary as an intermediary See Table, Slides 12-14

51 Octal to Hexadecimal (3 of 3)
10768 = ?16 E 10768 = 23E16

52 Hexadecimal to Octal (1 of 3)
Binary Hexadecimal

53 Hexadecimal to Octal (2 of 3)
Technique Use binary as an intermediary See Table, Slides 12-14

54 Hexadecimal to Octal (3 of 3)
1F0C16 = ?8 1 F C 1F0C16 =

55 Exercise – Convert ... Decimal Binary Octal Hexa- decimal 33 1110101
703 1AF Don’t use a calculator! Skip answer Answer

56 Exercise – Convert (answers)
Decimal Binary Octal Hexa- decimal 33 100001 41 21 117 165 75 451 703 1C3 431 657 1AF

57 Common Powers (1 of 2) Base 10 Power Preface Symbol pico p nano n
10-12 pico p 10-9 nano n 10-6 micro 10-3 milli m 103 kilo k 106 mega M 109 giga G 1012 tera T Value .001 1000

58 Common Powers (2 of 2) Base 2 What is the value of “k”, “M”, and “G”?
Preface Symbol 210 kilo k 220 mega M 230 Giga G Value 1024 What is the value of “k”, “M”, and “G”? In computing, particularly w.r.t. memory, the base-2 interpretation generally applies

59 Example 1. Double click on My Computer 2. Right click on C: 3. Click on Properties / 230 =

60 For common bases, add powers
Multiplying powers For common bases, add powers ab  ac = ab+c 26  210 = 216 = 65,536 or… 26  210 = 64  210 = 64k

61 Table of powers Power Base 8 7 6 5 4 3 2 1 256 128 64 32 16 32,768
256 128 64 32 16 32,768 4,096 512 65,536

62 Number point or radix point
Fractions Number point or radix point Decimal point in base 10 Binary point in base 2 No exact relationship between fractional numbers in different number bases Exact conversion may be impossible

63 Decimal fractions Move the number point one place to the right
Effect: multiplies the number by the base number Example: Move the number point one place to the left Effect: divides the number by the base number Example:

64 Fractions: Base 10 .258910 10-1 10-2 10-3 10-4 Place 10-1 10-2 10-3
Place 10-1 10-2 10-3 10-4 Value 1/10 1/100 1/1000 1/10000 Evaluate 2 x 1/10 5 x 1/100 8 x 1/1000 9 x1/10000 Sum .2 .05 .008 .0009

65 Fractions: Base 2 .1010112 = 0.67187510 2-1 2-2 2-3 2-4 2-5 2-6 Place
= 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 Evaluate 1 x 1/2 0 x 1/4 1x 1/8 0 x 1/16 1 x 1/32 1 x 1/64 Sum .5 0.125

66 Fractions: Base 10 and Base 2
No general relationship between fractions of types 1/10k and 1/2k 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/2k can be represented in base 10 Fractional conversions from one base to another are stopped If there is a rational solution, or When the desired accuracy is attained

67 Fractions: From Base B To Base 10
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: .A116 = 10x x16-2 = 10x x =

68 Fractions: From Base 10 To Base B
Multiply the fraction by the base value B (i.e., 2, 8 or 16) Record the values that move to the left of the radix point and drop them Repeat the process until the value being multiplied is zero, or the desired number of digits of accuracy is attained

69 Fractions: From Base 10 To Base B
= ? x

70 Fractions: From Base 2 To Base 8, 16
Group digits from left to right in groups of 3 (base 8) or 4 (base 16) Supplement the right-most group with 0’s, if necessary Convert each group to the desired base. See Table, Slides 12-14

71 Fractions: From Base 8, 16 To Base 2
Convert each octal (base 8) or hexadecimal (base 16) digit to its 3-bit or 4-bit representation See Table, Slides 12-14

72 Fractions: between Base 8 and Base 16
Use binary conversion as an intermediary Example: 0.C816 = ?8 C816 = 0.628

73 Mixed number conversion
Convert whole part and fraction part separately See Table, Slides 12-14

74 Arithmetic operations (1 of 14)
Binary Addition Two 1-bit values A B A + B 1 10 0 and carry 1 to the next more significant bit, i.e. “two”

75 Arithmetic operations (2 of 14)
Two n-bit values Add individual bits (see Table) Propagate carries 1 1 Note: superscripts are carried amounts.

76 Addition (different bases) (3 of 14)
Problem Largest Single Digit Decimal 6 +3 9 Octal +1 7 Hexadecimal +9 F Binary 1 +0

77 Addition (different bases) (4 of 14)
Problem Carry Answer Decimal 6 +4 Carry the 10 10 Octal +2 Carry the 8 Hexadecimal +A Carry the 16 Binary 1 +1 Carry the 2

78 Addition Table: Base 10 (5 of 14)
= 910 + 1 2 3 4 5 6 7 8 9 10 11 12 8 etc 13

79 Addition Table: Base 8 (6 of 14)
= 118 + 1 2 3 4 5 6 7 10 11 12 13 14 15 16

80 Arithmetic operations (7 of 14)
Binary Subtraction Two 1-bit values A B A - B 1 and borrow 1 from the next more significant bit

81 Arithmetic operations (8 of 14)
Two n-bit values Subtract individual bits (see Table) Keep track of the borrowings – = 10

82 Arithmetic operations (9 of 14)
Multiplication Decimal (just for fun) 35 x

83 Arithmetic operations (10 of 14)
Binary multiplication, two 1-bit values A B A  B 1

84 Arithmetic operations (11 of 14)
Binary multiplication, two n-bit values As with decimal values x

85 Multiplication Table: Base 10 (12 of 14)
310 x 610 = 1810 x 1 2 3 4 5 6 7 8 9 10 12 14 16 18 15 21 24 27 20 28 32 36 25 30 35 40 45 42 48 54 49 56 63 etc.

86 Multiplication Table: Base 8 (13 of 14)
38 x 68 = 228 x 1 2 3 4 5 6 7 10 12 14 16 11 17 22 25 20 24 30 34 31 36 43 44 52 61

87 Arithmetic operations (14 of 14)
Binary division, two n-bit values As with decimal values 100001/11 = ) quotient 1011 11 dividend 00100 divisor 11 11 11

88 Shifting a number 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

89 Thank you! Reading: Lecture slides and notes, Chapter 3


Download ppt "Lecture 2 Number Systems"

Similar presentations


Ads by Google