880 likes | 971 Views
Decimal. Octal. Binary. Hexadecimal. ITEC 1000 “Introduction to Information Technology”. Lecture 2. Number Systems. Lecture Template:. Types of number systems Number bases Range of possible numbers Conversion between number bases Common powers Arithmetic in different number bases
E N D
Decimal Octal Binary Hexadecimal ITEC 1000 “Introduction to Information Technology” Lecture 2 Number Systems
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
Types of Number Systems • Additive: Numbers have intrinsic value: e.g.: Roman Numerals: LVIII = 50 + 5 + 1 + 1 + 1 = 58 • Positional: Value depends on position: e.g.: Decimal system: 54 = 5 x 10 + 4 x 1 • Additive Number Systems are not used much any more: • Awkward to use. • Prone to errors.
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
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
Magnetic Core Memory http://en.wikipedia.org/wiki/Computer
Positional decimal system The number 125 means: 1 group of 100 (100 = 102) 2 groups of 10 (10 = 101) 5 groups of 1 (1 = 100)
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 7 3 2 3 groups of 1000 7 groups of 100 3 groups of 10 2 groups of 1
Place values (2 of 2) Weight 12510 => 5 x 100 = 5 2 x 101 = 20 1 x 102 = 100 125 Base
Representing in bases: 10, 2, 8, 16 • 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 Note: The subscript naming the base is itself given in base ten (10), by convention. Base
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
Decimal Range for Bit Widths See also Ch. 2, p.33
Decimal Octal Binary Hexadecimal Conversion Among Bases
Decimal Octal Binary Hexadecimal Binary to Decimal (1 of 3)
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
Bit “0” 1010112 => 1 x 20 = 1 1 x 21 = 2 0 x 22 = 0 1 x 23 = 8 0 x 24 = 0 1 x 25 = 32 4310 Binary to Decimal (3 of 3)
Octal to Decimal (1 of 3) Decimal Octal Binary Hexadecimal
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, 81 = 8, 82 = 64 83 = 512, Etc.
Octal to Decimal (3 of 3) 7248 => 4 x 80 = 4 x 1 = 4 2 x 81 = 2 x 8 = 16 7 x 82 = 7 x 64 = 448 46810
Hexadecimal to Decimal (1 of 3) Decimal Octal Binary Hexadecimal
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 = 256 163 = 4096, Etc.
Hexadecimal to Decimal (3 of 3) ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560 274810
Decimal to Binary (1 of 3) Decimal Octal Binary Hexadecimal
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.
2 125 62 1 2 31 0 2 15 1 2 3 1 2 7 1 2 0 1 2 1 1 Decimal to Binary (3 of 3) 12510 = ?2 12510 = 11111012
Octal to Binary (1 of 3) Decimal Octal Binary Hexadecimal
Octal to Binary (2 of 3) • Technique • Convert each octal digit to a 3-bit equivalent binary representation See Table, Slides 12-14
7 0 5 111 000 101 Octal to Binary (3 of 3) 7058 = ?2 7058 = 1110001012
Hexadecimal to Binary (1 of 3) Decimal Octal Binary Hexadecimal
Hexadecimal to Binary (2 of 3) • Technique • Convert each hexadecimal digit to a 4-bit equivalent binary representation See Table, Slides 12-14
1 0 A F 0001 0000 1010 1111 Hexadecimal to Binary (3 of 3) 10AF16 = ?2 10AF16 = 00010000101011112
Decimal to Octal (1 of 3) Decimal Octal Binary Hexadecimal
Decimal to Octal (2 of 3) • Technique • Divide by 8 • Keep track of the remainder
8 19 2 8 2 3 8 0 2 Decimal to Octal (3 of 3) 123410 = ?8 8 1234 154 2 123410 = 23228
Decimal to Hexadecimal (1 of 3) Decimal Octal Binary Hexadecimal
Decimal to Hexadecimal (2 of 3) • Technique • Divide by 16 • Keep track of the remainder
16 1234 77 2 16 4 13 = D 16 0 4 Decimal to Hexadecimal (3 of 3) 123410 = ?16 123410 = 4D216
Binary to Octal (1 of 3) Decimal Octal Binary Hexadecimal
Binary to Octal (2 of 3) • Technique • Group bits in threes, starting on right • Convert to octal digits See Table, Slides 12-14
1 011 010 111 1 3 2 7 Binary to Octal (3 of 3) 10110101112 = ?8 10110101112 = 13278
Binary to Hexadecimal (1 of 3) Decimal Octal Binary Hexadecimal
Binary to Hexadecimal (2 of 3) • Technique • Group bits in fours, starting on right • Convert to hexadecimal digits See Table, Slides 12-14
Binary to Hexadecimal (3 of 3) 10101110112 = ?16 10 1011 1011 2 B B 10101110112 = 2BB16
Octal to Hexadecimal (1 of 3) Decimal Octal Binary Hexadecimal
Octal to Hexadecimal (2 of 3) • Technique • Use binary as an intermediary See Table, Slides 12-14