protected int encode(double value,double lower,double upper,int nbits){
  if (value < lower)   return 0;
  int maxval=(int)(Math.pow(2,nbits) - 1);
  if (value >= upper)   return maxval;
  return (int)((value - lower) * ((maxval - 0) / (upper - lower)));
}

protected int encode ( double value , double lower , double upper , int nbits ) { if ( value < lower ) return 0 ; int maxval = ( int ) ( Math . pow ( 2 , nbits ) - 1 ) ; if ( value >= upper ) return maxval ; return ( int ) ( ( value - lower ) * ( ( maxval - 0 ) / ( upper - lower ) ) ) ; }
encode value as an nbits unsigned integer
