Decimal / Binary Conversions By Dr. JJ Shepherd
Number Systems A set of symbols to represent values Each number system has a set of symbols (digits or characters) representing a value Each system has a base which represents the base symbols in the system The symbol’s position indicates its order of magnitude Values are the summation of symbols multiplied by their base to the power of an exponent corresponding to their position
Decimal System Most commonly used system It is Base 10 Symbols are {0,1,2,3,4,5,6,7,8,9} Each value in this system can be expressed as a sum of each value multiplied by an exponent of 10 Example: 365 = 3x102 + 6x101 + 5x100
Binary System Commonly used in computing It is Base 2 Symbols are {0,1} Each value in this system can be expressed as a sum of each value multiplied by an exponent of 2 Example: 101 = 1x22 + 0x21 + 1x20
Binary to Decimal Using the same idea from the previous slide, expand the number by its factors Then sum together that expression into the decimal system Example 101 = 1x22 + 0x21 + 1x20 = 5 1101 = 1x23 + 1x22 + 0x21 + 1x20 = 13
Decimal to Binary 11 / 2 = 5 R 1 5 / 2 = 2 R 1 2 / 2 = 1 R 0 Going in the other direction requires division of the base Integer divide the value by 2 Record the remainder Repeat this until the value is 0 Reversing the remainders give the binary number Examples 11 / 2 = 5 R 1 5 / 2 = 2 R 1 2 / 2 = 1 R 0 1 / 2 = 0 R 1 HALT! 11 = 1011 13 / 2 = 6 R 1 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 HALT! 13 = 1101 365 / 2 = 182 R 1 182 / 2 = 91 R 0 91 / 2 = 45 R 1 45 / 2 = 22 R 1 22/ 2 = 11 R 0 11 / 2 = 5 R 1 5 / 2 = 2 R 1 2 / 2 = 1 R 0 1 / 2 = 0 R 1 HALT! 365 = 101101101 32 / 2 = 16 R 0 16 / 2 = 8 R 0 8 / 2 = 4 R 0 4 / 2 = 2 R 0 2 / 2 = 1 R 0 1 / 2 = 0 R 1 HALT! 32 = 100000 42 / 2 = 21 R 0 21 / 2 = 10 R 1 10 / 2 = 5 R 0 5 / 2 = 2 R 1 2 / 2 = 1 R 0 1 / 2 = 0 R 1 HALT! 32 = 101010