static function numBitsDiffering($a, $b) { $a ^= $b; // a now has a 1 bit exactly where its bit differs with b's // Count bits set quickly with a series of lookups: return self::$BITS_SET_IN_HALF_BYTE[$a & 0xf] + self::$BITS_SET_IN_HALF_BYTE[intval(uRShift($a, 4) & 0xf)] + self::$BITS_SET_IN_HALF_BYTE[uRShift($a, 8) & 0xf] + self::$BITS_SET_IN_HALF_BYTE[uRShift($a, 12) & 0xf] + self::$BITS_SET_IN_HALF_BYTE[uRShift($a, 16) & 0xf] + self::$BITS_SET_IN_HALF_BYTE[uRShift($a, 20) & 0xf] + self::$BITS_SET_IN_HALF_BYTE[uRShift($a, 24) & 0xf] + self::$BITS_SET_IN_HALF_BYTE[uRShift($a, 28) & 0xf]; }
/** * <p>Gets the requested bit, where true means black.</p> * * @param $x; The horizontal component (i.e. which column) * @param $y; The vertical component (i.e. which row) * @return value of given bit in matrix */ public function get($x, $y) { $offset = intval($y * $this->rowSize + $x / 32); if (!isset($this->bits[$offset])) { $this->bits[$offset] = 0; } // return (($this->bits[$offset] >> ($x & 0x1f)) & 1) != 0; return (uRShift($this->bits[$offset], $x & 0x1f) & 1) != 0; //было >>> вместо >>, не знаю как эмулировать беззнаковый сдвиг }