Completed
Push — master ( 81b3a8...48a269 )
by Camilo
02:13
created

str2bin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
/*
4
 * Nothing special in this file, just some common settings for each of the examples
5
 */
6
7
declare(strict_types = 1);
8
chdir(__DIR__ . '/../');
9
10
include __DIR__.'/../vendor/autoload.php';
11
12
error_reporting(E_ALL);
13
ini_set('display_errors', '1');
14
15
const COMMON_TOPICNAME = 'firstTest';
16
17
function str2bin($str)
18
{
19
    $out=null;
20
    $strLength = \strlen($str);
21
    for($a=0; $a < $strLength; $a++) {
22
        $dec = \ord(substr($str,$a,1)); //determine symbol ASCII-code
23
        $bin = sprintf('%08d', base_convert($dec, 10, 2)); //convert to binary representation and add leading zeros
24
        $out .= $bin;
25
    }
26
    return $out;
27
}
28