Passed
Pull Request — master (#7)
by Shinji
12:52
created

UInt64::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Lib\Integer;
15
16
/**
17
 * Class UInt64
18
 * @package PhpProfiler\Lib
19
 */
20
final class UInt64
21
{
22
    public int $hi;
23
    public int $lo;
24
25
    /**
26
     * UInt64 constructor.
27
     * @param int $hi
28
     * @param int $lo
29
     */
30
    public function __construct(int $hi, int $lo)
31
    {
32
        $this->hi = $hi;
33
        $this->lo = $lo;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function __toString()
40
    {
41
        $hi_hex = str_pad(base_convert((string)$this->hi, 10, 16), 8, '0', STR_PAD_LEFT);
42
        $lo_hex = str_pad(base_convert((string)$this->lo, 10, 16), 8, '0', STR_PAD_LEFT);
43
        return base_convert($hi_hex . $lo_hex, 16, 10);
44
    }
45
46
    /**
47
     * do the wrong thing
48
     *
49
     * @return int
50
     */
51
    public function toInt(): int
52
    {
53
        return (int)(string)$this;
54
    }
55
56
    /**
57
     * @param int $bit_pos
58
     * @return bool
59
     */
60
    public function checkBitSet(int $bit_pos): bool
61
    {
62
        $binary = str_pad(base_convert((string)$this, 10, 2), 64, '0', STR_PAD_LEFT);
63
        return (bool)strrev($binary)[$bit_pos];
64
    }
65
}
66