Thread: finding the one's complement of a binary number?

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    20

    finding the one's complement of a binary number?

    i have an array of 1s and 0s to represent a binary number. i would like to be able to manipulate the array (or maybe create a new one if neccesary?) which will represent the one's complement of the binary number.

    can anybody help me with this?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What's wrong with ! ?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    20
    the NOT operator? I don't follow..lol

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, what do you think the ones' complement of a binary number is, then?

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    20
    Is the one's complement of a binary number just the bits flipped ? i.e 1 becomes 0 and 0 becomes 1?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by dre View Post
    Is the one's complement of a binary number just the bits flipped ? i.e 1 becomes 0 and 0 becomes 1?
    Yes.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I thought it was the '~' operator.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Yep "~" is the one's complement while "!" is for logical negation.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by nonoob View Post
    I thought it was the '~' operator.
    That would work, except for the "array of 1's and 0's" part.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding number in string
    By Ducky in forum C++ Programming
    Replies: 6
    Last Post: 08-03-2009, 01:39 PM
  2. Replies: 10
    Last Post: 04-26-2009, 02:46 PM
  3. Replies: 2
    Last Post: 02-08-2009, 09:26 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM