Decimal Octal
Binary
Hexadecimal
1
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
Positional:
Definitions The Base of a number system how many different digits (incl. zero) are used in the system.
0, 1 0, 1, 2, 3, 4 0, 1, 2, 3, 4, 5, 6, 7 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) 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
http://en.wikipedia.org/wiki/Computer
System Decimal
Base Symbols 10 0, 1, 9
Binary
Octal Hexadecimal
2
8 16
0, 1
0, 1, 7 0, 1, 9, A, B, F
No
No No
Yes
Yes Yes
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 = 20 = 100 125
Base
10
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 A716 = 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)
Hexadecimal
0 1
Decimal 0 1
Binary 0 1
Octal 0 1
2 3 4 5 6 7
2 3 4 5 6 7
2 3 4 5 6 7
12
Counting in bases (2 of 3)
Hexadecimal
8 9
Decimal 8 9
Octal 10 11
10 11 12 13 14 15
12 13 14 15 16 17
A B C D E F
13
Counting in bases (3 of 3)
Hexadecimal
10 11
Decimal 16 17
Octal 20 21
18 19 20 21 22 23
22 23 24 25 26 27
12 13 14 15 16 17
14
1101 01102 = 21410 1101 01102 > 19210 (128 + 64 + additional bits to the right)
Place
Value Evaluate Sum for Base 10
27
128 1 x 128 128
26
64 1 x 64 64
25
32 0 x 32 0
24
16 1 x16 16
23
8 0x8 0
22
4 1x4 4
21
2 1x2 2
20
1 0x1 0
15
R = BK where
R = range B = base K = number of digits
Digits
0+
Range
2 (0 and 1)
4
8 10 16 20 32 64 128
1+
2+ 3 4+ 6 9+ 19+ 38+
16 (0 to 15)
256 1,024 (1K) 65,536 (64K) 1,048,576 (1M) 4,294,967,296 (4G) Approx. 1.6 x 1019 Approx. 2.6 x 1038
17
Decimal
Octal
Binary
Hexadecimal
18
Binary to Decimal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
19
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
20
Binary to Decimal (3 of 3)
Octal to Decimal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
22
Octal to Decimal (2 of 3)
Technique
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, 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
= 4 = 16 = 448 46810
24
Hexadecimal to Decimal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
25
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
Hexadecimal to Decimal (3 of 3)
ABC16 =>
27
Decimal to Binary (1 of 3)
Decimal
Octal
Binary
Hexadecimal
28
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.
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 0 1 1 1 1 1
12510 = 11111012
30
Octal to Binary (1 of 3)
Decimal
Octal
Binary
Hexadecimal
31
32
Octal to Binary (3 of 3)
7058 = ?2
7 0 5
7058 = 1110001012
33
Hexadecimal to Binary (1 of 3)
Decimal
Octal
Binary
Hexadecimal
34
35
Hexadecimal to Binary (3 of 3)
10AF16 = ?2
1 0 A F
10AF16 = 00010000101011112
36
Decimal to Octal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
37
38
Decimal to Octal (3 of 3)
123410 = ?8 8 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
41
Decimal to Hexadecimal (3 of 3)
123410 = ?16
16 16 16 1234 77 4 0
2 13 = D 4
123410 = 4D216
42
Binary to Octal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
43
44
Binary to Octal (3 of 3)
10110101112 = ?8
10110101112 = 13278
45
Binary to Hexadecimal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
46
47
Binary to Hexadecimal (3 of 3)
10101110112 = ?16
10 1011 1011
10101110112 = 2BB16
48
Octal to Hexadecimal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
49
50
Octal to Hexadecimal (3 of 3)
10768 = ?16
1 0 7 6
001 2
000 3
111
110 E
10768 = 23E16
51
Hexadecimal to Octal (1 of 3)
Decimal
Octal
Binary
Hexadecimal
52
53
Hexadecimal to Octal (3 of 3)
1F0C16 = ?8
1 F 0 C
0001 1
1111 7 4
0000 1
1100 4
1F0C16 = 174148
54
Decimal 33
Binary 1110101
Octal
703
1AF
Dont use a calculator! Skip answer Answer
55
Decimal 33
Binary 100001
Octal 41
117
451 431
1110101
111000011 110101111
165
703 657
75
1C3 1AF
56
Preface pico
Symbol p
Value .000000000001
10-9
10-6 10-3 103 106 109 1012
nano
micro milli kilo mega giga tera
n
m k M G T
.000000001
.000001 .001 1000 1000000 1000000000 1000000000000
57
Power
210 220 230
Preface
kilo mega
Symbol
k M
Value
1024 1048576
Giga
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
/ 230 =
59
or
26 210 = 64 210 = 64k
60
Table of powers
Power Base 2
256
128
64
32
16
32,768
4,096
512
64
16
65,536 4,096
256
16
61
62
Decimal fractions
Fractions: Base 10
10-1 10-2 10-3 10-4
.258910
64
Fractions: Base 2
2-1 2-2 2-3 2-4 2-5 2-6
.1010112 = 0.67187510
Place
2-1 1/2 1 x 1/2 .5 2-2 1/4 0 x 1/4 2-3 1/8 1x 1/8 0.125 2-4 1/16 0 x 1/16 2-5 1/32 1 x 1/32 0.03125 2-6 1/64 1 x 1/64 0.015625
Value
Evaluate Sum
65
67
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
68
0.1010112
69
Group digits from left to right in groups of 3 (base 8) or 4 (base 16) Supplement the right-most group with 0s, if necessary Convert each group to the desired base.
70
Convert each octal (base 8) or hexadecimal (base 16) digit to its 3bit or 4-bit representation
71
Fractions: between Base 8 and Base 16 Use binary conversion as an intermediary Example: 0.C816 = ?8
1100 10002
6 2 0 0.C816 = 0.628
72
73
A 0 0 1 1
B 0 1 0 1
A+B 0 1 1 10
21 + 25 46
Problem 6 +3 6 +1 6 +9
Binary
1 +0
76
Problem 6 +4 6 +2 6 +A 1 +1
Answer 10 10 10 10
77
0
1 2 3 4
0
1 2 3 4
1
2 3 4 5
2
3 4 5 6
3
4 5 6 7
4
5 6 7 8
5
6 7 8 9
6
7 8 9 10
7
8 9 10 11
8
9 10 11 12
9
10 11 12 13
78
etc
38 + 68 = 118
+ 0 1 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 10
2
3 4 5 6 7
2
3 4 5 6 7
3
4 5 6 7 10
4
5 6 7 10 11
5
6 7 10 11 12
6
7 10 11 12 13
7
10 11 12 13 14
10
11 12 13 14 15
11
12 13 14 15 16
79
A 0 0 1 1
B 0 1 0 1
A-B 0 1 1 0
80
n-bit values
Subtract individual bits (see Table) Keep track of the borrowings 00100101 00010001 = 00010100
0 10
0
0
0
1
0
0
1
1
0
1
0
1
83
2
3 4 5 6 7 0
2
3 4 5 6 7
4
6 8 10 12 14
6
9 12 15 18 21
8
12 16 20 24 28
10
15 20 25 30 35
12
18 24 30 36 42
14
21 28 35 42 49
16
24 32 40 48 56
18
27 36 45 54 63
85
etc.
2
3 4 5 6 7 0
2
3 4 5 6 7
4
6 10 12 14 16
6
11 14 17 22 25
10
14 20 24 30 34
12
17 24 31 36 43
14
22 30 36 44 52
16
25 34 43 52 61
86
quotient
100001/11 = 1011
11 ) 100001 00100 11 11 11 0
divisor
dividend
87
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
88
Thank you!
Reading: Lecture slides and notes, Chapter 3
89