Thread: Bitwise Operations Help Please!

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    71

    Bitwise Operations Help Please!

    Currently my sort is not working properly because of some logic flaw in my bitwise operations.
    Code:
      while(index<4){
        for(i=0;i<size;i++){
          val=views[i]>>(index*group);
          mask = val&(0xff);
          printf("index=%i val=%i mask=%i views[i]=%i\n",index,val,mask,views[i]);
          count[mask]++;
        }
    }
    Here is 1 section of the output I am confused with.
    Code:
    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
    Posts
    71
    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
    Location
    The edge of the known universe
    Posts
    39,656
    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