In: Computer Science
Part 2: Signed values: Convert each as indicated.
7. Decimal to Hexadecimal (1 byte, signed magnitude)
a. -18
b. -41
a. -18 Decimal to binary: ------------------- Write down the decimal number and continually divide by 2 to give a result and a remainder. The remainder is either a 1 or a 0. 18 / 2 result 9 remainder 0 9 / 2 result 4 remainder 1 4 / 2 result 2 remainder 0 2 / 2 result 1 remainder 0 1 / 2 result 0 remainder 1 Read the remainders from bottom to top. ( 18 )10 = ( 10010 )2 Prepend zeros ro make it 8 bit. ( 18 )10 = ( 00010010 )2 Ones complement = Inverts bits in binary = 11101101 Twos complement = Ones complement + 1 = 11101101 + 1 = 11101110 Binary to hexa decimal: ------------------------ Convert each 4 bits to its hexa decimal. 1110 in hexa decimal is E So, 11101110 in hexa decimal = EE Answer: (EE)16 ****************************** b. -41 Decimal to binary: ------------------- Write down the decimal number and continually divide by 2 to give a result and a remainder. The remainder is either a 1 or a 0. 41 / 2 result 20 remainder 1 20 / 2 result 10 remainder 0 10 / 2 result 5 remainder 0 5 / 2 result 2 remainder 1 2 / 2 result 1 remainder 0 1 / 2 result 0 remainder 1 Read the remainders from bottom to top. ( 41 )10 = ( 101001 )2 Prepend zeros ro make it 8 bit. ( 41 )10 = ( 00101001 )2 Ones complement = Inverts bits in binary = 11010110 Twos complement = Ones complement + 1 = 11010110 + 1 = 11010111 Binary to hexa decimal: ------------------------ Convert each 4 bits to its hexa decimal. 1101 in hexa decimal is D 0111 in hexa decimal is 7 So, 11010111 in hexa decimal = D7 Answer: (D7)16