Guest User

Untitled

a guest
Aug 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public inline static function minBits(values: Array<Int>): Int {
  2.         var max_bits: Int = 0;
  3.         for(x in values) {
  4.             // Make sure x is positive!
  5.             if(x < 0) x = -x;
  6.  
  7.             // Compute most significant 1 bit
  8.             x |= (x >> 1);
  9.             x |= (x >> 2);
  10.             x |= (x >> 4);
  11.             x |= (x >> 8);
  12.             x |= (x >> 16);
  13.  
  14.             // Compute ones count (equals the number of bits to represent original value)
  15.             x -= ((x >> 1) & 0x55555555); //This integer(0x555555) is too big to be compiled to a Neko 31-bit integer. Please use a Float instead
  16.             x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
  17.             x = (((x >> 4) + x) & 0x0f0f0f0f);
  18.             x += (x >> 8);
  19.             x += (x >> 16);
  20.             x &= 0x0000003f;
  21.  
  22.             if(x > max_bits)
  23.                 max_bits = x;
  24.         }
  25.  
  26.         return max_bits;
  27.     }
Add Comment
Please, Sign In to add comment