Thread: What the heck does this mean/do

  1. #1
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    What the heck does this mean/do

    if (d >= 0)
    clipflags &= ~(1<<i);

    EDIT: I understand the bitshifting part (in this case multiplying by 2)

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    if d is 0 or positive:
    clipflags AND by two's complement by i

    notes:
    1*i=i
    two's complement=
    0 = 1
    1 = 0
    so:
    1011 will equal to 0100
    i do a bitwise AND

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    godammit! i hate the way i always make mistakes on my posts.

    1 is shifted i times to the left

    there, or multiplied by 2, i times. or 2^i (not XOR in this case, this is math now, lol)

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    actually ~ is bitwise not so what this does is shift 1 to the right to the i'th bit (counting from the least significant bit), negate or invert every bit (so every bit but the i'th is set) and and(heh) it with clipflags, having the effect of turning off the i'th bit and leaving the rest unchanged.

    the two's comliment of n is (~n)+1, remember the two's comliment of zero is zero.

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    well i wasn't wrong though....

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    No, it's just two's compliment has a different meaning. Technically ~ is one's compliment but no-one calls it that. To make life more fun people do call binary not or invert negate, and the most common form of signed integers uses two's compliment for negitive ints! I wasn't trying to be mean, take it as a compliment :P

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    lol, ok

    yea, u're rite. i said it wrong (two instead of one) but i explained it right. LOL, thanks

  8. #8
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    yeah, that's right. one's compliment is just flipping the bits. remember, if you want to do 2's compliment, you have to flip the bits then add 1.

    so:
    1011 ->2's compliment-> 0101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What the heck am I possibly doing wrong?
    By QuestionC in forum Tech Board
    Replies: 2
    Last Post: 04-29-2007, 08:43 PM
  2. how the heck do i ftp?
    By Waldo2k2 in forum Tech Board
    Replies: 9
    Last Post: 03-03-2003, 06:51 AM
  3. What the heck is wrong with my database?
    By Blizzarddog in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 10:51 AM
  4. What the heck is this? Hm?
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-26-2002, 09:19 PM
  5. what the HECK?!?!?!?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-26-2001, 08:12 PM