Convert byte
@return string byte
182315
function readByte($byte, $precision = 7)
    {
        $unit  = array('Byte','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB');

        if (is_numeric($byte)) {
            $w = floor((strlen($byte) - 1) / 3);
            return sprintf("%.{$precision}f %s", $byte/pow(1024, $w), $unit[$w]);
        }
        $str   = array_values(array_filter(explode(' ', $byte)));

        return array_shift($str)*pow(1024,
            (int) array_search(array_shift($str), $unit)).' '.$unit[0];
    }
390299
public function getHex64(): string
    {
        $result = '0x';
        for ($i = 7; $i >= 0; $i--) {
            $result .= sprintf('%02X', $this->bytes[$i]);
        }
        return $result;
    }
933444
def to_bytes(value):
    """"""
    if isinstance(value, unicode):
        return value.encode('utf8')
    elif not isinstance(value, str):
        return str(value)
    return value
20693
public function readVInt()
    {
        $nextByte = ord($this->_data[$this->_position++]);
        $val = $nextByte & 0x7F;

        for ($shift=7; ($nextByte & 0x80) != 0; $shift += 7) {
            $nextByte = ord($this->_data[$this->_position++]);
            $val |= ($nextByte & 0x7F) << $shift;
        }
        return $val;
    }
64386
public function byteSize()
    {
        return mb_strlen($this->name) +
                mb_strlen($this->type) +
                mb_strlen($this->value);
    }
350790
protected function encode(): string
    {
        $bitmap = null;
        $lastRow = null;

        for ($y = 0; $y < $this->height; $y++) {
            $bits = null;

            for ($x = 0; $x < $this->width; $x++) {
                $bits .= $this->decoder->getBitAt($x, $y);
            }

            $bytes = str_split($bits, 8);
            $bytes[] = str_pad(array_pop($bytes), 8, '0');

            $row = null;

            foreach ($bytes as $byte) {
                $row .= sprintf('%02X', bindec($byte));
            }

            $bitmap .= $this->compress($row, $lastRow);
            $lastRow = $row;
        }

        return $bitmap;
    }
436749
private function parseSignedInt16()
    {
        try {
            $result = \unpack('n', $this->buffer)[1];

            if ($result & 0x8000) {
                return $result - 0x10000;
            }

            return $result;
        } finally {
            $this->buffer = mb_orig_substr($this->buffer, 2);
        }
    }
755719
public function ToString()
	{
		$result = "";
		$format = "H:i:s";

		if ( ! @empty( $this->Value->microseconds != 0 ) )
		{
			$format .= "." . rtrim( $this->Value->microseconds, "0" );
		}

		if ( ! $this->IsLocal )
		{
			$format .= $this->Value->getOffset() == 0
	   		 	? "\Z"
	   			: "P";
		}

		return $this->Value->format( $format );
	}
119143
public function toBytes(): string
    {
        $bytes = '';
        $hex = $this->toHex();

        foreach (range(0, 30, 2) as $i) {
            $bytes .= chr(hexdec(substr($hex, $i, 2)));
        }

        return $bytes;
    }
1111391
public function to_bin()
   {
         $out = "";
      for ($i=0; $i<$this->dataLength($this->data); $i++)
         $out = sprintf("%08b",$this->data[$i]).$out;
      return $out;      
   }
1326175
protected byte[] byteBufferToByteArray() {
        if (byteBuffer.hasArray()) {
            return byteBuffer.array();
        } else {
            final byte[] byteArray = new byte[byteBuffer.remaining()];
            byteBuffer.get(byteArray);
            return byteArray;
        }
    }
261691
public function _encode()
    {
        $data = "";
        foreach ($this->byteArray as $byte)
        {
            $data .= chr($byte);
        }

        return array(
            '__type' => 'Bytes',
            'base64' => base64_encode($data)
        );
    }
186070
public function readDouble() {

            $double = $this->readBuffer(8);

            $testEndian = unpack("C*",pack("S*",256));
            $bigEndian = !$testEndian[1]==1;
                        
            if ($bigEndian) $double = strrev($double);
            $double = unpack("d",$double);
            return $double[1];
        }
965637
public function getBytes()
    {
        if ($this->bytes === null) {
            $this->bytes = array_map(
                function ($chunk) {
                    return (int) $chunk;
                },
                explode('.', $this->address)
            );
        }

        return $this->bytes;
    }
226350
public function fromBytes($bytes)
    {
        for ($i=0; $bytes >= 1024 && $i < 8; $i++) {
            $bytes /= 1024;
        }
        return round($bytes, 2) . $this->units[$i];
    }
282384
public function readDouble()
    {
        $bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, 8, '8bit') : substr($this->_stream, $this->_needle, 8);
        $this->_needle+= 8;

        if (!self::$_bigEndian) {
            $bytes = strrev($bytes);
        }

        $double = unpack('dflt', $bytes);
        $flt = $double['flt'];
        if(is_nan($flt))
            return null;
        else
            return $flt;
    }
320251
protected function convertToBytes($value)
    {
        $value = trim($value);
        $last  = strtolower($value[strlen($value) - 1]);

        switch ($last) {
            // The 'G' modifier is available since PHP 5.1.0
            case 'g':
                $value *= 1024;
                break;

            case 'm':
                $value *= 1024;
                break;

            case 'k':
                $value *= 1024;
                break;
        }

        return $value;
    }