Sha256: 4f5cacba8327032ad8ebb4c5353184e38bcbb4ca649b0e1a920cbdcd32ea26bd
Contents?: true
Size: 462 Bytes
Versions: 396
Compression:
Stored size: 462 Bytes
Contents
<?php /** * Converts binary value to a decimal. * * @param string $binary * * @return int */ function parse_binary($binary) { $reversed = strrev($binary); for ($i = 0, $decimal = 0; $i < strlen($reversed); ++$i) { if ($reversed[$i] !== '0' && $reversed[$i] !== '1') { throw new InvalidArgumentException('Invalid binary string.'); } $decimal += ((int) $reversed[$i]) * (2 ** $i); } return $decimal; }
Version data entries
396 entries across 396 versions & 1 rubygems