1. 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.
    Dismiss Notice

why is author adding 1 to the answer?

Discussion in 'Mathematics and Physics' started by PG1995, Oct 9, 2011.

  1. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,681
    Likes:
    13
    Hi

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

    Attached Files:

  2. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    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: Oct 9, 2011
  3. Ratchit

    Ratchit Well-Known Member

    Joined:
    Mar 12, 2008
    Messages:
    1,954
    Likes:
    83
    PG1995,

    I think he is doing an end around carry, which you do for ones complement arithmetic.
    http://www.electro-tech-online.com/custompdfs/2011/10/1sAnd2sComplement.pdf

    There is a far easier way do do negative numbers. Just convert them to positive numbers and add a minus sign. You can change the sign of ones complement numbers by simply complementing each bit.

    Ratch
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. JimB

    JimB Super Moderator Most Helpful Member

    Joined:
    Sep 11, 2004
    Messages:
    6,390
    Likes:
    592
    Location:
    Peterhead, Scotland

    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
     
    • Like Like x 1
  6. Ratchit

    Ratchit Well-Known Member

    Joined:
    Mar 12, 2008
    Messages:
    1,954
    Likes:
    83
    JimB,

    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.

    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.

    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
     
  7. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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: Oct 10, 2011
  8. Ratchit

    Ratchit Well-Known Member

    Joined:
    Mar 12, 2008
    Messages:
    1,954
    Likes:
    83
    CZ,

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

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

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

    Ratch
     
  9. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,681
    Likes:
    13
    Yes, this is what written in my book. That most computers these days use 2's complement.

    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
     
  10. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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.
     

Share This Page