binary conversions

I have a homework question here which asks me to convert a certain binary number (in twos complement) into a decimal number. Now the problem I'm having is the word decimal... normal when you convert a binary it becomes an integer, not a decimal!

What does it mean by decimal? do I just add .00 to the end or what? Say if my answer (after doing the maths to convert) becomes 180, do i just turn it into 180.00?

Also are they saying covert to base 10 or convert to base 2?

I've scoured my whole textbook an C++ and it only talks about converting to integers!
Last edited on
An integer is what you want. Decimal is the name of base 10, just like binary is the name of base 2.
So just to confirm... after I convert the binary to a whole number. eg. 180, then 180 is my "decimal" answer?

This is confusing. :(
that's correct.
2's complement is used to efficiently convey the notion of negative numbers to a computer. For example, a computer that reads only base two can't possibly read -1100₂ because the negative symbol is not a number. So, if a machine uses 1's complement, it knows that a 1 before a string of numbers represents a negative number. The problem with this is that the numbers 00000₂ and 10000₂ with this system would represent 0 and "-0", which is both a waste of space (two zeroes instead of one) and could confuse the system into thinking negative zero exists. As such, 2's complement was formed. 2's complement removes this extra negative zero by adding one to the complemented number.

Here's how it works:
The number 3₁₀ can be represented by 11₂. In a 2's complement system, the number 3₁₀, since it's not negative, is represented by 011₂, think if the first 0 as a + sign.
The number -3₁₀ can be represented by -11₂, but a computer can't understand the - sign, so we need to 2's complement this. To do that, we first must put a 1 to the front of the number to denote a - sign. Then, we flip every bit after the first 1 (flipping is necessary in 2's complement). Then, we add 1 to the number, now we have our 2's complement of -3_1₀! (-11₂ > 111₂ > 100₂ > 101₂)

So, for your problem.
1010₂ implies that the number is negative. Now, we just reverse the process we just took for -3₁₀. So subtract 1 from the 1010₂, and we get 1001₂. Now flip every bit after the first 1, and we get 1110₂. Now replace the first 1 with the more people-friendly negative sign. We now have -110₂. This converts to -6₁₀.

Binary numbers work like this:
0₂=0₁₀
1₂=1₁₀
10₂=2₁₀
11₂=3₁₀
100₂=4₁₀
101₂=5₁₀
110₂=6₁₀
111₂=7₁₀
1000₂=8₁₀
and so on...
Just got another question in regards to a final decimal number... say with my example of 180 above. Do I have to add the log base 10 in afterwards? For example 180 = 180(10)

Because from the tests that we have done in class, we just leave it as say 180 and we are marked correct, but someone told me it's better to add in a log base 10 value?
yes you must put log after the number.. because of that you can see in which base that number is.. ;)
Topic archived. No new replies allowed.