-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBitMask.php
More file actions
53 lines (46 loc) · 1.15 KB
/
Copy pathBitMask.php
File metadata and controls
53 lines (46 loc) · 1.15 KB
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
<?php
namespace PhpBinaryReader;
use PhpBinaryReader\Exception\InvalidDataException;
class BitMask
{
const MASK_LO = 0;
const MASK_HI = 1;
/**
* @var array
*/
private $bitMasks = [
[0x00, 0xFF],
[0x01, 0x7F],
[0x03, 0x3F],
[0x07, 0x1F],
[0x0F, 0x0F],
[0x1F, 0x07],
[0x3F, 0x03],
[0x7F, 0x01],
[0xFF, 0x00]
];
/**
* @return array
*/
public function getBitMasks()
{
return $this->bitMasks;
}
/**
* @param int $bit
* @param int $type
* @return mixed
* @throws Exception\InvalidDataException
*/
public function getMask($bit, $type)
{
$bit = (int) $bit >= 0 && (int) $bit <= 8 ? $bit : 0;
if ($type == self::MASK_LO) {
return $this->getBitMasks()[$bit][self::MASK_LO];
} elseif ($type == self::MASK_HI) {
return $this->getBitMasks()[$bit][self::MASK_HI];
} else {
throw new InvalidDataException('You can only request a lo or hi bit mask using this method');
}
}
}