value_min_bits
/*
** 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) );
}
** 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) );
}
[Please Login]
Projects: 3
Contributors: Leif902, xot
comments powered by Disqus

Related: