Conditions | 3 |
Paths | 3 |
Total Lines | 15 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
49 | public function flipBits(string $bitString): string |
||
50 | { |
||
51 | $length = strlen($bitString); |
||
52 | |||
53 | if ($length % 8 !== 0) { |
||
54 | throw new \Exception('Bit string length must be a multiple of 8'); |
||
55 | } |
||
56 | |||
57 | $newString = ''; |
||
58 | for ($i = $length; $i >= 0; $i -= 8) { |
||
59 | $newString .= substr($bitString, $i, 8); |
||
60 | } |
||
61 | |||
62 | return $newString; |
||
63 | } |
||
64 | } |
||
65 |