Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- x -= ((x >> 1) & 0x55555555); //This integer(0x555555) is too big to be compiled to a Neko 31-bit integer. Please use a Float instead
- 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;
- }
Add Comment
Please, Sign In to add comment