Thread: Bitwise Operations Help Please!

  1. #1
    Registered User
    Join Date
    Oct 2012

    Bitwise Operations Help Please!

    Currently my sort is not working properly because of some logic flaw in my bitwise operations.
          mask = val&(0xff);
          printf("index=%i val=%i mask=%i views[i]=%i\n",index,val,mask,views[i]);
    Here is 1 section of the output I am confused with.
    index=1 val=0 mask=0 views[i]=5
    index=1 val=513 mask=1 views[i]=131341
    index=1 val=0 mask=0 views[i]=33
    index=1 val=0 mask=0 views[i]=55
    index=1 val=1562 mask=26 views[i]=400000
    index=1 val=1684 mask=148 views[i]=431341
    index=1 val=1218 mask=194 views[i]=312050
    Why is it that ANDing 1218 with 0xff gives a higher number than ANDing 1684 with 0xff and 1562 with 0xff??
    I don't understand this part and this is probably what is messing up my sort. Any suggestions, comments, or ideas?

  2. #2
    Registered User
    Join Date
    Oct 2012
    EDIT: I actually found the error and it was in another part of my code. Is there a way to delete a thread?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Threads just get abandoned when the answer is found, or everybody gets fed up of posting to it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise operations
    By sh3rpa in forum C++ Programming
    Replies: 16
    Last Post: 09-25-2007, 06:32 PM
  2. bitwise operations
    By black_watch in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 04:48 AM
  3. bitwise operations
    By barneygumble742 in forum C Programming
    Replies: 10
    Last Post: 09-11-2004, 10:33 AM
  4. bitwise operations
    By andrew_tucker in forum C Programming
    Replies: 2
    Last Post: 11-28-2002, 12:46 AM
  5. bitwise operations in C
    By samps005 in forum C Programming
    Replies: 5
    Last Post: 10-10-2002, 03:35 PM