decimalcomplement

Finding the decimal value of numbers in Two's and One's Complement


I want to turn a negative float number into decimal one but I dont know how to do it. for example I got the number 101.1011 and I need to find the decimal value in Two's complement ( the answer supposed to be -2.3125) and in One's complement (-2.25)


Solution

  • I assume you know what binary numbers represent in general. For Two's complement you just have to know that the left-most bit is also telling you if the number is negative or positive.

    So for the Two's complement of your example it would be:
    -(22) + 20 = -4 + 1 = -3 for the integer part (left-side of the decimal point) and 2-1 + 2-3 + 2-4 = 0.5 + 0.125 + 0.0625 = 0.6875. So, you get -3 + 0.6875 = -2.3125.

    For One's complement you look at the left-most bit, that tells you it is a negative number. So you invert every bit and take the left-most bit as sign-bit (ignore its value). Then you compute it as a normal binary number.

    For your example this would be: 101.1011 -> -10.0100 = -(21) + 2-2 = -2.25