educative.io

Binary to decimal conversion bug

My calculator says binary representation of -10 is “1111111111111111111111111111111111111111111111111111111111111110”. But when I paste this value in Binary value text box in the course, the decimal value displayed is “18446744073709552000” instead of -10.

Hi @Kartheek_Penagamuri,

Thanks for your cooperation, but this is not a bug. This binary to decimal converter only supports positive number conversations.

There are two types of binary number representations: signed and unsigned. In the lesson, the unsigned binary numbers have been explained i.e they are all positive integers. However, in signed integers, we need to represent both positive and negative integers. For this, the most significant bit represents the sign of the integer - 0 for positive and 1 for negative - and the remaining bits represent the numerical value of the number in case of a positive integer and its two’s complement in case of a negative integer.
For instance, consider the binary number 111. As an unsigned number, it represents 12^2 + 12^1 + 1*2^0 = 7. In signed notation, the MSB is 1 so the integer is negative. The two’s complement of the remaining bits, 11 is 01 which equals 1 in decimal. Hence, in signed notation, 111 equals -1.

First of all, you can find the binary of 10, which is 1010 in 4 bits and 00001010 in 8 bits.
Because you want to find the binary of -10 then you will take 2’s complement of positive 10’s binary. So first, you will invert all bits of positive 10’s binary then add 1 in it.
1’s complement of 00001010 is 11110101,
now add 1 in it 11110101 + 1 = 11110110 = -10

Now coming on your question, “1111111111111111111111111111111111111111111111111111111111111110” is not a binary of -10.
In signed 2’s complement representation, it is equal to “-2”.
In unsigned representation, it is equal to “18446744073709551614”.
I think, it only supports unsigned conversion functionality.