Conversion Between Decimal and Binary Representations
Conversion Between Decimal and Binary Representations
R. Mukundan
Department of Computer Science and Software Engineering University of Canterbury, Christchurch, New Zealand.
128
64 32
16
Example: 1101 = 8x1 + 4x1 + 1x1 (or simply, 8+4+1) = 13 The position-value of the nth bit from right is 2n-1. Method 2: The advantage of this method is that you need not remember or compute position-values. Starting from leftmost bit, multiply the first bit by 2 and add to the next. Multiply the result by 2 and add to the third bit. Multiply the result by 2 and add to the fourth bit. Continue this process till you have reached the rightmost bit. Example: 1101 1 1 0 1
Exercise: Convert the following binary numbers to decimal: 111 11001 10010110
R. Mukundan (2008)
1
64 32 16 8 4 2 1
11 8 = 3
128 64
1
32 16
1
8 4 2 1
32=1
The process stops when you get a remainder 1 or 0, and this number occupies the last bit position. 1 0 1 0 1 1 Method 2: In this method, we repeatedly divide the given decimal number by 2, and the remainders are placed from right to left: Example: 43 43 2: Quotient 21, remainder 1: Result > 21 2: Quotient 10, remainder 1: Result > 10 2: Quotient 5, remainder 0: Result > 5 2: Quotient 2, remainder 1: Result > 2 2: Quotient 1, remainder 0: Result > 1 2: Quotient 0, remainder 1: Result > The process stops when the quotient becomes 0 1 11 011 1011 01011 101011
R. Mukundan (2008)