Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte map[32]={0,0……0};
- int len=strlen(string);
- //PrepareMap
- for(int i=0;i<len;i++)
- map[(string[i])>>3] |= 1<<( (string[i]) &7)
- //deciding whether a character (ch) is in string
- if ( (map[ch>>3] & (1<<(ch&7))) !=0 )
- //ch is in string
- else
- //ch is not in string
- In the above program, some bit operators are used. Here are their meanings:
- op1 >> op2: shift the bits in op1 to the right for op2 bits; neither op1 nor op2 is affected
- op1 << op2: shift the bits in op1 to the left for op2 bits; neither op1 nor op2 is affected
- op1 & op2: perform bit-wise AND operation between each pair of matching bits
- in op1 and op2; neither op1 nor op2 is affected
- op1 | op2: perform bit-wise OR operation between each pair of matching bits
- in op1 and op2; neither op1 nor op2 is affected
Add Comment
Please, Sign In to add comment