2's complement (1 Viewer)

HY2000

New member
Local time
Yesterday, 23:44
Joined
Jun 27, 2018
Messages
8
Q: Find the decimal valued for the following 8 bit bit patterns:
10000010 in 2's complement representation


I would like to ask if I need to change 10000010 to 2's complement before I calculate the decimal value, or the 10000010 is already changed to 2's complement form?

Welcome of further discussion, Thankyou!!
 

June7

AWF VIP
Local time
Yesterday, 22:44
Joined
Mar 9, 2014
Messages
5,470
I interpret the instruction to first change to 2's complement then determine the decimal. But don't take my word, ask your instructor.
 

HY2000

New member
Local time
Yesterday, 23:44
Joined
Jun 27, 2018
Messages
8
But how can I know I need to do the 2's complement first. It is hard to see in the question, at first I think it is a grammatical problem
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:44
Joined
Feb 28, 2001
Messages
27,179
This is obviously a question for a programming class.

Here is your problem. There is NO DIFFERENCEin appearance between 2's complement and sign-value numbers when given the binary pattern. Oh, they mean 2 different numbers - but looking at it, you cannot tell. Therefore, you are lucky that your problem TELLS you that the bit pattern IS in 2's complement format.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:44
Joined
Feb 28, 2001
Messages
27,179
Just for the record, it happens that unsigned integers and 2's complement integers can use the same addition rules (in binary) but they have to use different tests to determine whether anything anomalous occurred.

For instance, if you have 8-bit pattern 1111 1111 and you add 0000 0001 to it, you get bit pattern 0000 0000. But the first question is whether this was a signed or an unsigned number. What you do is look at individual column overflows, or carries. Binary addition of two operands involves 4 bits per column. Two bits for the binary digits that are in the operands, one bit for the binary digit that is your answer, and one bit for overflow. (Because 001 + 001 is actually 010, because the left-most column produced a 0 and an overflow that carried into the next column.

To finish this long story, if you have signed numbers, then the most significant bit (MSB) is the sign bit. You had an overflow if the carry into and out of the MSB DON'T match.

If you had unsigned numbers, then you had an overflow when the carry out of the MSB (which is NOT the sign bit... unsigned, remember?) was 1.

The part that is significant is that if you use 2's complement, there is no special logic required for the binary adder. 2 addends, a sum, and a carry bit for each column. Same rules for each. And rather than worry about subtraction logic, the CPU just internally generates the 2's complement of the number and then adds it. So a SUBTRACT hardware instruction is internally (usually) implemented as NEGATE, ADD (in that order.)

The REAL fun is that with a binary shifter and the 2's complement adder, you can also do multiplication. But I'll leave that exercise for the curious insomniacs among you.
 

Users who are viewing this thread

Top Bottom