Guest User

Untitled

a guest
Apr 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. byte map[32]={0,0……0};
  2.  
  3. int len=strlen(string);
  4.  
  5. //PrepareMap
  6. for(int i=0;i<len;i++)
  7. map[(string[i])>>3] |= 1<<( (string[i]) &7)
  8.  
  9.  
  10. //deciding whether a character (ch) is in string
  11. if ( (map[ch>>3] & (1<<(ch&7))) !=0 )
  12. //ch is in string
  13. else
  14. //ch is not in string
  15.  
  16.  
  17. In the above program, some bit operators are used. Here are their meanings:
  18. op1 >> op2: shift the bits in op1 to the right for op2 bits; neither op1 nor op2 is affected
  19. op1 << op2: shift the bits in op1 to the left for op2 bits; neither op1 nor op2 is affected
  20. op1 & op2: perform bit-wise AND operation between each pair of matching bits
  21. in op1 and op2; neither op1 nor op2 is affected
  22. op1 | op2: perform bit-wise OR operation between each pair of matching bits
  23. in op1 and op2; neither op1 nor op2 is affected
Add Comment
Please, Sign In to add comment