In: Computer Science
Convert the following decimal numbers to 16-bit 2’s complement binary. Display your result in hexadecimal.
a.3030
b.404
c.5050
d.-5050
e.-20000
Show work with steps
a) Since this is a positive number. we can directly convert this into binary Divide 3030 successively by 2 until the quotient is 0 3030/2 = 1515, remainder is 0 1515/2 = 757, remainder is 1 757/2 = 378, remainder is 1 378/2 = 189, remainder is 0 189/2 = 94, remainder is 1 94/2 = 47, remainder is 0 47/2 = 23, remainder is 1 23/2 = 11, remainder is 1 11/2 = 5, remainder is 1 5/2 = 2, remainder is 1 2/2 = 1, remainder is 0 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 101111010110 Adding 4 zeros on left hand side of this number to make this of length 16 so, 3030 in 2's complement binary is 0000101111010110 Converting 0000101111010110 to hexadecimal 0000 => 0 1011 => B 1101 => D 0110 => 6 So, in hexadecimal 0000101111010110 is 0x0BD6 b) Since this is a positive number. we can directly convert this into binary Divide 404 successively by 2 until the quotient is 0 404/2 = 202, remainder is 0 202/2 = 101, remainder is 0 101/2 = 50, remainder is 1 50/2 = 25, remainder is 0 25/2 = 12, remainder is 1 12/2 = 6, remainder is 0 6/2 = 3, remainder is 0 3/2 = 1, remainder is 1 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 110010100 Adding 7 zeros on left hand side of this number to make this of length 16 so, 404 in 2's complement binary is 0000000110010100 Converting 0000000110010100 to hexadecimal 0000 => 0 0001 => 1 1001 => 9 0100 => 4 So, in hexadecimal 0000000110010100 is 0x0194 c) Since this is a positive number. we can directly convert this into binary Divide 5050 successively by 2 until the quotient is 0 5050/2 = 2525, remainder is 0 2525/2 = 1262, remainder is 1 1262/2 = 631, remainder is 0 631/2 = 315, remainder is 1 315/2 = 157, remainder is 1 157/2 = 78, remainder is 1 78/2 = 39, remainder is 0 39/2 = 19, remainder is 1 19/2 = 9, remainder is 1 9/2 = 4, remainder is 1 4/2 = 2, remainder is 0 2/2 = 1, remainder is 0 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 1001110111010 Adding 3 zeros on left hand side of this number to make this of length 16 so, 5050 in 2's complement binary is 0001001110111010 Converting 0001001110111010 to hexadecimal 0001 => 1 0011 => 3 1011 => B 1010 => A So, in hexadecimal 0001001110111010 is 0x13BA d) This is negative. so, follow these steps to convert this into a 2's complement binary Step 1: Divide 5050 successively by 2 until the quotient is 0 5050/2 = 2525, remainder is 0 2525/2 = 1262, remainder is 1 1262/2 = 631, remainder is 0 631/2 = 315, remainder is 1 315/2 = 157, remainder is 1 157/2 = 78, remainder is 1 78/2 = 39, remainder is 0 39/2 = 19, remainder is 1 19/2 = 9, remainder is 1 9/2 = 4, remainder is 1 4/2 = 2, remainder is 0 2/2 = 1, remainder is 0 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 1001110111010 Adding 3 zeros on left hand side of this number to make this of length 16 So, 5050 in normal binary is 0001001110111010 Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0. 0001001110111010 is flipped to 1110110001000101 Step 3:. Add 1 to above result 1110110001000101 + 1 = 1110110001000110 so, -5050 in 2's complement binary is 1110110001000110 Converting 1110110001000110 to hexadecimal 1110 => E 1100 => C 0100 => 4 0110 => 6 So, in hexadecimal 1110110001000110 is 0xEC46 e) This is negative. so, follow these steps to convert this into a 2's complement binary Step 1: Divide 20000 successively by 2 until the quotient is 0 20000/2 = 10000, remainder is 0 10000/2 = 5000, remainder is 0 5000/2 = 2500, remainder is 0 2500/2 = 1250, remainder is 0 1250/2 = 625, remainder is 0 625/2 = 312, remainder is 1 312/2 = 156, remainder is 0 156/2 = 78, remainder is 0 78/2 = 39, remainder is 0 39/2 = 19, remainder is 1 19/2 = 9, remainder is 1 9/2 = 4, remainder is 1 4/2 = 2, remainder is 0 2/2 = 1, remainder is 0 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 100111000100000 Adding 1 zeros on left hand side of this number to make this of length 16 So, 20000 in normal binary is 0100111000100000 Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0. 0100111000100000 is flipped to 1011000111011111 Step 3:. Add 1 to above result 1011000111011111 + 1 = 1011000111100000 so, -20000 in 2's complement binary is 1011000111100000 Converting 1011000111100000 to hexadecimal 1011 => B 0001 => 1 1110 => E 0000 => 0 So, in hexadecimal 1011000111100000 is 0xB1E0