1's and 2's complement

This is a discussion on 1's and 2's complement within the C Programming forums, part of the General Programming Boards category; When I was studying C programming (long time ago). There were something about negative value called 1's and 2's complement. ...

  1. #1
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187

    1's and 2's complement

    When I was studying C programming (long time ago). There were something about negative value called 1's and 2's complement. I don't remember, what are they. Could anyone please explain, in order that I can recall them.
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    32
    Here is a crazy idea that seems to have caught on in this day and age:
    Google
    Beware the fury of a patient man.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    One's compliment simple reverses the bits in a value:
    10010111 becomes 01101000
    It's the compliment created by the NOT operator !

    Two's compliment reverses then adds one to the value:
    10010111 becomes 01101001
    This is the function of the negate operator -

    So to create a negative value, the compiler will use the two's compliment:
    000001
    111110 -- NOT the value
    111111 -- add 1
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    Deeply thanks, WaltP.
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Negative numbers in C
    By BlaX in forum C Programming
    Replies: 18
    Last Post: 06-29-2009, 06:30 PM
  2. Bitwise OR
    By tinkerbell20 in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2005, 02:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21