In: Computer Science
What is the 11 bit, binary representation of -108? What is the hexadecimal equivalent of this number?
Answer in binary: 11110010100 Answer in hexadecimal: 0x794 Explanation: ------------- -108 This is negative. so, follow these steps to convert this into a 2's complement binary Step 1: Divide 108 successively by 2 until the quotient is 0 > 108/2 = 54, remainder is 0 > 54/2 = 27, remainder is 0 > 27/2 = 13, remainder is 1 > 13/2 = 6, remainder is 1 > 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 1101100 So, 108 of decimal is 1101100 in binary So, 108 in normal binary is 00001101100 Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0. 00001101100 is flipped to 11110010011 Step 3:. Add 1 to above result 11110010011 + 1 = 11110010100 so, -108 in 2's complement binary is 11110010100 Adding 1 zeros on left hand side of this number to make it's length a multiple of 4 Hexadecimal Binary 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 Use this table to convert from binary to hexadecimal Converting 011110010100 to hexadecimal 0111 => 7 1001 => 9 0100 => 4 So, in hexadecimal 011110010100 is 0x794