
Untitled
By: a guest on
May 28th, 2012 | syntax:
ActionScript 3 | size: 0.72 KB | hits: 17 | expires: Never
public inline static function minBits(values: Array<Int>): Int {
var max_bits: Int = 0;
for(x in values) {
// Make sure x is positive!
if(x < 0) x = -x;
// Compute most significant 1 bit
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
// Compute ones count (equals the number of bits to represent original value)
// This integer is too big to be compiled to a Neko 31-bit integer. Please use a Float instead
x -= ((x >> 1) & 0x55555555);
x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
x = (((x >> 4) + x) & 0x0f0f0f0f);
x += (x >> 8);
x += (x >> 16);
x &= 0x0000003f;
if(x > max_bits)
max_bits = x;
}
return max_bits;
}