Helper to retrieve the hexadecimal representation of a message.

@return string
487690
public function toHex($prefixHexContent = false)
    {
        $chars = $this->getPlain();
        if ($prefixHexContent && ctype_xdigit($chars)) {
            return "fe" . $chars;
        }

        $payload = "";
        for ($c = 0, $cnt = strlen($chars); $c < $cnt; $c++ ) {
            $decimal = ord($chars[$c]);
            $hexCode = dechex($decimal);

            // payload is built of *hexits*
            $payload .= str_pad($hexCode, 2, "0", STR_PAD_LEFT);
        }

        $this->payload = strtolower($payload);
        return $this->payload;
    }
488841
public static function v4(): string
	{
		$random = random_bytes(16);

		$random[6] = chr(ord($random[6]) & 0x0f | 0x40);

		$random[8] = chr(ord($random[8]) & 0x3f | 0x80);

		return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($random), 4));
	}
1154823
public function toHexString($length = 8)
    {
        if ($length === 8) {
            return $this->__toString();
        }
        return '#' . substr(bin2hex(pack('N', $this->toRgba())), 0, 6);
    }
676103
public function getTextSID($binsid)
    {
        $hex_sid = bin2hex($binsid);

        $rev = hexdec(substr($hex_sid, 0, 2));

        $subcount = hexdec(substr($hex_sid, 2, 2));

        $auth = hexdec(substr($hex_sid, 4, 12));

        $result = "$rev-$auth";

        $subauth = [];

        for ($x = 0;$x < $subcount; $x++) {
            $subauth[$x] = hexdec($this->littleEndian(substr($hex_sid, 16 + ($x * 8), 8)));

            $result .= '-'.$subauth[$x];
        }

        // Cheat by tacking on the S-
        return 'S-'.$result;
    }
734436
def hex(self):
        """"""
        props = self._message_properties()
        msg = bytearray([MESSAGE_START_CODE_0X02, self._code])

        for prop in props:
            # pylint: disable=unused-variable
            for key, val in prop.items():
                if val is None:
                    pass
                elif isinstance(val, int):
                    msg.append(val)
                elif isinstance(val, Address):
                    if val.addr is None:
                        pass
                    else:
                        msg.extend(val.bytes)
                elif isinstance(val, MessageFlags):
                    msg.extend(val.bytes)
                elif isinstance(val, bytearray):
                    msg.extend(val)
                elif isinstance(val, bytes):
                    msg.extend(val)
                elif isinstance(val, Userdata):
                    msg.extend(val.bytes)

        return binascii.hexlify(msg).decode()
25320
@Override
    public String getMessage() {
        String message = super.getMessage();

        if (message == null) {
            message = "";
        }

        if (hexdump != null) {
            return message + (message.length() > 0 ? " " : "") + "(Hexdump: "
                    + hexdump + ')';
        }

        return message;
    }
581184
public function getId()
    {
        return sprintf(
          '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
          mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
          mt_rand(0, 0x0fff) | 0x4000,
          mt_rand(0, 0x3fff) | 0x8000,
          mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
        );
    }
123062
private function hex16(){
        $val = dechex(floor((1 + ((float)rand()/(float)getrandmax())) * 0x10000));
        return substr($val,0,-1);
    }
3348
public String getDecodedMessage()
    {
        if (message == null)
        {
            return null;
        }
        return new String(Base64.base64ToByteArray(message), Charset.forName("UTF-8"));
    }
968663
public function getFormat()
    {
        switch (true) {
            case ($this->encoder instanceof Base32Encoder):
                $format = self::FORMAT_BASE32;
                break;
            case ($this->encoder instanceof HexEncoder):
                $format = self::FORMAT_HEX;
                break;
            case ($this->encoder instanceof RawEncoder):
            default:
                $format = self::FORMAT_RAW;
        }

        return $format;
    }
481645
public function toPlain($hex = null)
    {
        if (empty($this->payload) && empty($hex))
            return "";

        $plain = "";
        $payload = $hex ?: $this->payload;
        for ($c = 0, $cnt = strlen($payload); $c < $cnt; $c += 2) {
            $hex = substr($payload, $c, 2);
            $decimal = hexdec($hex);
            $plain  .= chr($decimal);
        }

        return ($this->plain = $plain);
    }
72718
public function number(): string
    {
        $num = gmp_import($this->_flags, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
        $last_octet_bits = $this->_width % 8;
        $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
        $num >>= $unused_bits;
        return gmp_strval($num, 10);
    }
433444
public function getOrigBody()
    {
        $_headers = $this->message->headers();
        $headers  = array();

        if ($_headers['Content-Transfer-Encoding']
            && stripos($_headers['Content-Type'], 'multipart') === false
        ) {
            $headers[] = 'Content-Transfer-Encoding: ' . $_headers['Content-Transfer-Encoding'];
        }
        $headers[] = 'Content-Type: ' . $_headers['Content-Type'];

        return implode("\r\n", $headers) . "\r\n\r\n" . $this->body;
    }
114593
public function serialize()
    {
        if (is_null($this->bin)) {
            return '';
        }

        $length_prefixed_bin = strlen($this->bin) . ':' . $this->bin;

        if (is_null($this->key)) {
            return $length_prefixed_bin . ':';
        }
        return $length_prefixed_bin . ':' . $this->key;
    }
597876
public static function get()
    {
        mt_srand((int) (microtime(true) * 1000));

        $b = md5(uniqid(mt_rand(), true), true);
        $b[6] = chr((ord($b[6]) & 0x0F) | 0x40);
        $b[8] = chr((ord($b[8]) & 0x3F) | 0x80);

        return implode('-', unpack('H8a/H4b/H4c/H4d/H12e', $b));
    }
826621
protected function hexstr($hex)
    {
        $string = '';
        for ($i = 0; $i < strlen($hex) - 1; $i += 2) {
            $string .= chr(hexdec($hex[$i].$hex[$i + 1]));
        }

        return $string;
    }
262178
private function intToHex($i)
    {
        // Sanitize the input.
        $i = (int) $i;

        // Get the first character of the hexadecimal string if there is one.
        $j = (int) ($i / 16);

        if ($j === 0) {
            $s = ' ';
        } else {
            $s = strtoupper(dechex($j));
        }

        // Get the second character of the hexadecimal string.
        $k = $i - $j * 16;
        $s = $s . strtoupper(dechex($k));

        return $s;
    }