blob: 0b4ff6a77845e619fa36858eb3b8df09d549a6cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?php
/**
* Class BitBuffer
*
* @filesource BitBuffer.php
* @created 25.11.2015
* @package chillerlan\QRCode\Helpers
* @author Smiley <[email protected]>
* @copyright 2015 Smiley
* @license MIT
*/
namespace chillerlan\QRCode\Helpers;
use function count, floor;
class BitBuffer{
/**
* @var int[]
*/
public $buffer = [];
/**
* @var int
*/
public $length = 0;
/**
* @return \chillerlan\QRCode\Helpers\BitBuffer
*/
public function clear():BitBuffer{
$this->buffer = [];
$this->length = 0;
return $this;
}
/**
* @param int $num
* @param int $length
*
* @return \chillerlan\QRCode\Helpers\BitBuffer
*/
public function put(int $num, int $length):BitBuffer{
for($i = 0; $i < $length; $i++){
$this->putBit((($num >> ($length - $i - 1)) & 1) === 1);
}
return $this;
}
/**
* @param bool $bit
*
* @return \chillerlan\QRCode\Helpers\BitBuffer
*/
public function putBit(bool $bit):BitBuffer{
$bufIndex = floor($this->length / 8);
if(count($this->buffer) <= $bufIndex){
$this->buffer[] = 0;
}
if($bit === true){
$this->buffer[(int)$bufIndex] |= (0x80 >> ($this->length % 8));
}
$this->length++;
return $this;
}
}
|