130 likes | 393 Views
Positional number systems 1.- Decimal number system 2.- Binary number system 3.- Hexadecimal number system 4.- Base conversions. COP 2500 Concepts in Computer Science. Positional number systems
E N D
Positional number systems 1.- Decimal number system 2.- Binary number system 3.- Hexadecimal number system 4.- Base conversions COP 2500 Concepts in Computer Science
Positional number systems When we need to write the number three hundred and twenty five using decimal digits we use the following sequence of digits: 325 What do we know about this number? It is written using decimal digits (a digit from 0 to 9 in decimal notation), which means that the base of the decimal number system is 10 (the decimal system has ten symbols or digits). Formally we can write 325 as: 3 x 102 + 2 x 101 + 5 x 100 = (3 x 100) + (2 x 10) + (5 x 1) = 300 + 20 + 5 = 325 Note that 100 = 1 COP 2500 Concepts in Computer Science
Positional number systems Formally we can write 325 as: 3 x 102 + 2 x 101 + 5 x 100 = (3 x 100) + (2 x 10) + (5 x 1) = 300 + 20 + 5 = 325 Note that 100 = 1 By denoting the base of the system as b = 10, we can rewrite 325 as: 325 = 3 x b2 + 2 x b1 + 5 x b0 For any number we will refer to each digit by “di”, where “d” represents the digit and “i” indicates the position in the sequence. Thus we have that any number can be represented by a sequence of digits: dn dn-1 . . . d2 d1 d0 In our example, d2 = 3, d1 = 2, and d0 = 5 COP 2500 Concepts in Computer Science
Positional number systems Therefore any number can be represented by a sequence of digits: dn . . . d2 d1 d0 And its value can be computed as follows: dn . . . d2 d1 d0 = dn x bn. . . d2 x b2 + d1 x b1 + d0 x b0 Example: d3 d2 d1 d0 4 7 6 2 COP 2500 Concepts in Computer Science
Positional number systems Binary numbers can be represented in the same way: (dn . . . d2 d1 d0 )2 Indicates that the base (b) is binary And its value can be computed similarly but in this case the base b = 2. dn . . . d2 d1 d0 = dn x bn. . . d2 x b2 + d1 x b1 + d0 x b0 Example: (10101)2 = 1 x 24 + 0 x 23 + 1 x 22 + 0 x 21 + 1 x 20 1 x 16 + 0 x 8 + 1 x 4 + 0 x 2 + 1 x 1 16 + 0 + 4 + 0 + 1 = (21)10 COP 2500 Concepts in Computer Science
The following table shows the decimal, binary, and hexadecimal representation of the first 16 decimal numbers: Decimal Binary Hexadecimal 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F COP 2500 Concepts in Computer Science As we have used up all decimal symbols, we need to use letters to represent some digits in the Hexadecimal system.
From hexadecimal to binary As each hexadecimal number can be represented by four binary digits, then to convert an hexadecimal number to binary we proceed as follows: (7AF3)16 = ( ?)2 Starting from left to right each hexadecimal digit is replaced by its binary representation: 7 = 0111 A = 1010 F = 1111 3 = 0011 0111 1010 1111 0011 Note: see the table in the previous slide. COP 2500 Concepts in Computer Science
From binary to hexadecimal We need to convert the following binary number to hexadecimal: (10111110111000)2 = ( ?)16 Starting from right to left we make groups of four bits. If the last group on the right has less than four bits we add some padding zeros. 10111110111000 0010 1111 1011 1000 2FB8 COP 2500 Concepts in Computer Science
COP 2500 Concepts in Computer Science From binary to hexadecimal We need to convert the following binary number to hexadecimal: (10111110111000)2 = ( ?)16 Starting from right to left we make groups of four bits. If the last group on the right has less than four bits we add some padding zeros. 10111110111000 0010 1111 1011 1000 2FB8
COP 2500 Concepts in Computer Science Convert from decimal to binary: for example, (147)10 = ( ? )2 2 |147 1 2|73 1 2|36 0 2|18 0 2|9 1 2|4 0 2|2 0 2|1 1 0 Read from bottom to top the number is: (10010011)2
COP 2500 Concepts in Computer Science Octal System { 0, 1, 2, 3, 4, 5, 6, 7}