Binary to decimal conversion

The binary number $1000111$ converted in decimal is equal to $71$ or to $-71$? The binary number has $1$ as the first left number so I thought it could mean that in decimal it is negative.

Also, the two's complement of $1000111$ is $0111001$. $0111001$ is equal to $57$ or $-57$?

I hope someone can clarify this for me.

• "The binary number has 1 as the first left number so I thought it could mean that in decimal it is negative." All numbers have a one as their first digit, not counting leading zeros, and obviously not counting zero (which has no value besides leading zeros). So the idea that one represents negative is clearly false. (What is true is that a leading one indicates a negative number if that one is in a specific location, such as the first spot of an 8-bit or 16-bit number, and if there is a convention that identifies that location should be treated like a sign bit.) – TOOGAM Mar 5 '18 at 6:56

Without any assumptions, the number is $1000111_2 = 2^6+2^2+2^1+2^0 = 71$. If you wanted $-71$ it would just be $-1000111$. $1000111$ is no more negative than $99$.

That said, in practice we have a fixed number of bits we can use. Nevertheless this still doesn't tell you that $1000111$ is $-71$ because it could be an unsigned representation.

Additionally, there are other ways to represent negative numbers besides two's complement.

Finally, even if this were two's complement and this was the maximum number of bits available it still wouldn't be $-71$ since that's not how we interpret negative numbers in two's complement. If you want to know what the "negative" of this number is, you invert all the bits and add 1. So $-1$ in a four-bit representation would be $0001\rightarrow 1110 + 1 = 1111$. With this in mind, the arithmetic inverse of your number would be $0111000 + 1 = 111001_2 = 57$ as you indicate towards the end of your post. Therefore our original number $1000111$ in 7-bit two's complement is $-57$

• Nice, covers everything. – fleablood Feb 13 '18 at 17:48

"The binary number has 1 as the first left number so I thought it could mean that in decimal it is negative. "

Why would you think that?

We can make up any rules to for what the terms in a binary string mean that we want. We can make the increasing powers of two be increasing right to left or left to right or interspersing in odd vs even places.

So it wouldn't surprise me if there is some programming convention that to represent negative numbers if the leftmost digit is $1$. If heard of conventions where the the strings $00000000$ to $01111111$ represent the numbers $0$ to $127$ whereas $10000000$ to $11111111$ represent the numbers from $-128$ to $-1$.

I have never heard of a system where $01$ represents $1$ and $1$ represents $-1$ and $011$ represents $3$ while $11$ represent $-3$ and $01000111$ represents $71$ while $1000111 but such a system could exist and would be consistent. But as far as MATHEMATICS goes, the rule is simply that the powers of$2$increase for right to left and$1000111=01000111$is$71$and there is no way to represent negatives except with a negative sign. So, what programming convention are you using. • The programming convention that you mention exists and is called "two's complement": en.wikipedia.org/wiki/Two%27s_complement – Connor Harris Feb 13 '18 at 17:18 • Not quite. two's complement is a fixed length to would only be a 1 in the eighths (or furthest left of a fixed length) place that indicate negative and that would be the negative of the complement not the number. That would be the system in my fourth paragraph. I've never heard of the system in my fifth paragraph or as described by the OP and I doubt it exists. I guess it couldn't because if 0 = off 1= on there is nothing for non-existant so 01x and 1x can never be distinguished. – fleablood Feb 13 '18 at 17:46 The definition for converting a number from base 2 (binary) to base 10 (decimal) is as follows: We consider the string of$1$'s and$0$'s from$right$to$left$. We start at the right most digit and apply the rule: Let$a_n a_{n-1} ... a_2a_1$represent the binary form of a decimal number$a$. Then we have to consider n cases. Case 1: If$a_1 = 1$, then we count it as$2^0$. Otherwise if$a_1 = 0$, we count it as$0$. Case 2: If$a_2 = 1$, then we count it as$2^1$. Otherwise if$a_1 = 0$, we count it as$0$. In general, Case n: If$a_n = 1$, then we count it as$2^{n-1}$. Otherwise if$a_1 = 0$, we count it as$0$. Finally, we sum over all$n$cases for the decimal conversion. As per your example,$(1000111)_{2} = (2^{0} + 2^{1} + 2^{2} + 0 + 0 + 0 + 2^{6})_{10} = (71)_{10}\$