Bits

get and set bit

public boolean is set(int n, int index) {
   return (n & (1<<index) ) > 0;
}

public void set(int n, int index, boolean b) {
  if (b) {
    n = n | (1<<index)
  } else {
   int mask  = ~(1<<index);
   n = n & mask
  }
}

http://interview.googlecode.com/svn/trunk/java/lru.java

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License