Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: ActionScript 3  |  size: 0.72 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. // This integer is too big to be compiled to a Neko 31-bit integer. Please use a Float instead
  16.                         x -= ((x >> 1) & 0x55555555);
  17.                         x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
  18.                         x = (((x >> 4) + x) & 0x0f0f0f0f);
  19.                         x += (x >> 8);
  20.                         x += (x >> 16);
  21.                         x &= 0x0000003f;
  22.  
  23.                         if(x > max_bits)
  24.                                 max_bits = x;
  25.                 }
  26.                 return max_bits;
  27.         }