1 | <?php |
||
7 | class BinaryMath |
||
8 | { |
||
9 | /** |
||
10 | * @var GmpMathInterface |
||
11 | */ |
||
12 | private $math; |
||
13 | |||
14 | /** |
||
15 | * @param GmpMathInterface $math |
||
16 | */ |
||
17 | 21 | public function __construct(GmpMathInterface $math) |
|
21 | |||
22 | /** |
||
23 | * @param int $bitSize |
||
24 | * @return int |
||
25 | */ |
||
26 | 21 | private function fixSize($bitSize) |
|
30 | |||
31 | /** |
||
32 | * @param \GMP $integer |
||
33 | * @param int $bitSize |
||
34 | * @return bool |
||
35 | */ |
||
36 | 21 | public function isNegative(\GMP $integer, $bitSize) |
|
40 | |||
41 | /** |
||
42 | * @param \GMP $integer |
||
43 | * @param int $bitSize |
||
44 | * @return \GMP |
||
45 | */ |
||
46 | public function makeNegative(\GMP $integer, $bitSize) |
||
47 | { |
||
48 | return $this->math->bitwiseXor($this->math->leftShift(gmp_init(1), $this->fixSize($bitSize)), $integer); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param \GMP $integer |
||
53 | * @param int $bitSize |
||
54 | * @return \GMP |
||
55 | */ |
||
56 | public function getTwosComplement(\GMP $integer, $bitSize) |
||
60 | } |
||
61 |