BitArray.php
1 week ago
BitMatrix.php
1 week ago
BitUtils.php
1 week ago
CharacterSetEci.php
1 week ago
EcBlock.php
1 week ago
EcBlocks.php
1 week ago
ErrorCorrectionLevel.php
1 week ago
FormatInformation.php
1 week ago
Mode.php
1 week ago
ReedSolomonCodec.php
1 week ago
Version.php
1 week ago
index.php
1 week ago
BitUtils.php
36 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WP2FA_Vendor\BaconQrCode\Common; |
| 5 | |
| 6 | /** |
| 7 | * General bit utilities. |
| 8 | * |
| 9 | * All utility methods are based on 32-bit integers and also work on 64-bit |
| 10 | * systems. |
| 11 | */ |
| 12 | final class BitUtils |
| 13 | { |
| 14 | private function __construct() |
| 15 | { |
| 16 | } |
| 17 | /** |
| 18 | * Performs an unsigned right shift. |
| 19 | * |
| 20 | * This is the same as the unsigned right shift operator ">>>" in other |
| 21 | * languages. |
| 22 | */ |
| 23 | public static function unsignedRightShift(int $a, int $b) : int |
| 24 | { |
| 25 | return $a >= 0 ? $a >> $b : ($a & 0x7fffffff) >> $b | 0x40000000 >> $b - 1; |
| 26 | } |
| 27 | /** |
| 28 | * Gets the number of trailing zeros. |
| 29 | */ |
| 30 | public static function numberOfTrailingZeros(int $i) : int |
| 31 | { |
| 32 | $lastPos = \strrpos(\str_pad(\decbin($i), 32, '0', \STR_PAD_LEFT), '1'); |
| 33 | return $lastPos === \false ? 32 : 31 - $lastPos; |
| 34 | } |
| 35 | } |
| 36 |