value_min_bits

Downloadvalue_min_bits(n,size)   Returns the smallest number of bits that can be used to store the given value.
/*
**  Usage:
**      value_min_bits(n,size)
**
**  Arguments:
**      n       value, positive integer
**      size    word size, positive integer (optional)
**
**  Returns:
**      the smallest number of bits that can be used to store the given value,
**      if a word size is given, the value returned is expressed in words
**
**  Example:
**      value_min_bits(1000)   == 10 bits
**      value_min_bits(1000,8) == 2 bytes
**
**  GMLscripts.com
*/

{
    return ceil( floor( logn(2,argument0) + 1 ) / max(1,argument1) );
}

Click if you've used this script[Please Login]
Projects: 3


comments powered by Disqus