code: protected static long setBits(long num, int start, int len, long value){
      // Get rid of illegal bits of value:
      value = value & ((1L<<len)-1);
      
      long val_mask = value << start;
      long zero_mask = ~( ((1L << len) -1) << start );
      return ( num & zero_mask ) | val_mask;
    }
docs: Sets specific bits of a specific number.
  @param num The number to set bits.
  @param start Index of the rightmost bit we want to set. 0-based.
  @param len How many bits we want to set.
  @param value The value we want to set to.
  @return The number after changing specific bits.