Completed
Push — master ( 63c267...6b14e5 )
by Michael
02:13
created

Support::hex2bin()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
crap 12
1
<?php
2
3
/**
4
 * Support.php
5
 * 
6
 * PHP version 7
7
 * 
8
 * @category Dcrypt
9
 * @package  Dcrypt
10
 * @author   Michael Meyer (mmeyer2k) <[email protected]>
11
 * @license  http://opensource.org/licenses/MIT The MIT License (MIT)
12
 * @link     https://github.com/mmeyer2k/dcrypt
13
 */
14
15
namespace Dcrypt;
16
17
/**
18
 * Provides numeric data conversion helper functions.
19
 * 
20
 * @category Dcrypt
21
 * @package  Dcrypt
22
 * @author   Michael Meyer (mmeyer2k) <[email protected]>
23
 * @license  http://opensource.org/licenses/MIT The MIT License (MIT)
24
 * @link     https://github.com/mmeyer2k/dcrypt
25
 * @link     https://apigen.ci/github/mmeyer2k/dcrypt/namespace-Dcrypt.html
26
 */
27
class Support
28
{
29
    /**
30
     * Turns an integer into a 4 byte binary representation
31
     * 
32
     * @param int $dec Integer to convert to binary
33
     * 
34
     * @return string
35
     */
36 5
    protected static function dec2bin(int $dec): string
37
    {
38 5
        return hex2bin(\str_pad(\dechex($dec), 8, '0', STR_PAD_LEFT));
39
    }
40
41
    /**
42
     * Reverses dec2bin
43
     * 
44
     * @param string $bin Binary string to convert to decimal
45
     * 
46
     * @return string
47
     */
48 3
    protected static function bin2dec($bin)
49
    {
50 3
        return \hexdec(\bin2hex($bin));
51
    }
52
}
53