Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

why is author adding 1 to the answer?

Status
Not open for further replies.

PG1995

Active Member
Hi

Please check the attachment. You can find my question there. Thank you.
 

Attachments

  • IMG_0001.jpg
    IMG_0001.jpg
    609.5 KB · Views: 329
Hi,

It looks like that's because the number is negative, while the previous number was positive.

It looks like another way to compute this when the number is negative is as follows:

11000

where the leftmost bit is the sign bit and this number is negative, you take the right 4 bits:

1000

and that equals 8 decimal, so the number is -8. Pretty simple that way.

This means zero can be represented as 00000 or 11111.

Positive 8 would be 01000.

I've never actually had to use 1's complement in any programming i ever did since the mid 1970's when microprocessors where just getting popular, even in specially designed programming equipment where we had the choice of what system to use. I've always used 2's complement for everything, including assembler, Pascal, Basic, C, C++, Windows API, etc.
 
Last edited:
Just to state what may have already been said but in a slightly different way which my poor brain understands.

An 8 bit byte can count from 0 (00000000) to 255 (11111111).
In this case all the numbers are positive integers.

If you want to use negative numbers, as well as positive, we need some way to signify a negative number.
This is done using the most significant bit. ie 1xxxxxxx is a negative number, and 0xxxxxxx is a positive number.

To create a negative number, you just take the 2's complement of the positive number.
To create the 2's complement:

step 1, invert all the bits (creating the 1's complement)

step 2, add 1. (creating the 2's complement)

Example
What is -14 in binary?

14 is 00001110

Take the 1's complement 11110001

Take the 2's complement 11110010

So, -14 is 11110010

To prove that -14 is 11110010, and it to +14 (00001110)
and you will get 00000000, and the carry bit will also be set off the most significant end of the byte.

I think that just about makes sense!

JimB
 
JimB,

An 8 bit byte can count from 0 (00000000) to 255 (11111111).
In this case all the numbers are positive integers.

If you want to use negative numbers, as well as positive, we need some way to signify a negative number.
This is done using the most significant bit. ie 1xxxxxxx is a negative number, and 0xxxxxxx is a positive number.

Yes, they are called signed and unsigned numbers. You have to know what type of number a binary is before you can convert to decimal. It is a matter of interpretation.

To create a negative number, you just take the 2's complement of the positive number.
To create the 2's complement:

step 1, invert all the bits (creating the 1's complement)

step 2, add 1. (creating the 2's complement)

You mean to say the negative of a 2's complement number. You cannot tell just be looking at a binary whether it is 1's or 2's complement. It is a matter in interpretation. It also affects the way you add or subtract the numbers. With a 2's complement, you don't worry about the end-arround-carry. You can also get the negative of a 1's complement by just inverting all the bits.

To prove that -14 is 11110010, and it to +14 (00001110)
and you will get 00000000, and the carry bit will also be set off the most significant end of the byte.

I think that just about makes sense!

Yes, and for 1's complement, 00001110 + 11110001 = 11111111, which is zero for 1's complement. Remember that 1's complement has two representations for zero.

Ratch
 
Just to add a practical element to this discussion, are there even any systems which use one's complement? Aren't all computer systems used today based on two's complement?

Just read the summary of the two systems in my textbook: one's complement is clumsy because it has two values for zero (0 and FF for an 8-bit number). Only con for two's complement is that there is one more negative number than positive (-80H vs +7FH).
 
Last edited:
CZ,

Just to add a practical element to this discussion, are there even any systems which use one's complement? Aren't all computer systems used today based on two's complement?

No, some of the mainframes do, like the Unisys 1100/2200 series.

Just read the summary of the two systems in my textbook: one's complement is clumsy because it has two values for zero (0 and FF for an 8-bit number).

Not so bad, hardware usually translates all 1's into 0.

Only con for two's complement is that there is one more negative number than positive (-80H vs +7FH).

Yes, the zero takes up one place in the positive number range. I think the extra negative number is a bonus.

Ratch
 
Just to add a practical element to this discussion, are there even any systems which use one's complement? Aren't all computer systems used today based on two's complement?

Yes, this is what written in my book. That most computers these days use 2's complement.

Just read the summary of the two systems in my textbook: one's complement is clumsy because it has two values for zero (0 and FF for an 8-bit number). Only con for two's complement is that there is one more negative number than positive (-80H vs +7FH).

FF = 1111 1111 = 255

How can you say that "1111 1111" would equate to zero?

-80H = -128
+7FH = +127

Yes, you are right. We have 128 negative numbers, and 127 which are -ve. Zero is considered neither -ve nor +ve.

By the way, why are 1's complement and 2's complement called so? I mean what would it mean when I say 3's complement?

Thank you for your help. Please note that most the time I add extra details (which you people might find redundant) for my own later reference.

Regards
PG
 
FF = 1111 1111 = 255

How can you say that "1111 1111" would equate to zero?

FF, or 11111111, is only = to 255 (decimal) if you treat it as an unsigned 8-bit number. Unsigned numbers can only have positive values (the "sign bit" is just part of the number).

For negative quantities we need to use signed numbers; as defined by one's complement, FF = 0 (because remember, there are 2 values of zero in that system, 11111111 and 00000000). In two's complement, it's -128.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top