Convert hex to string.

@param  string  $hex

@return string
343111
protected static function fromHex(string $hex): string
    {
        $data = '';

        // Convert hex to string.
        for ($i = 0; $i < \strlen($hex) - 1; $i += 2) {
            $data .= \chr(\hexdec($hex[$i].$hex[$i + 1]));
        }

        return $data;
    }
394430
public function hex($hex)
    {
        list($red, $green, $blue) = $this->hexToRGB($hex);

        $this->rgb($red, $green, $blue);

        return $this;
    }
463735
public function setFromHex($hex, $alpha = 0)
    {
        if (!preg_match(self::$HexRegex, $hex)) {
            throw new \InvalidArgumentException(sprintf(
                    'Inavlid Hex Color "%s"', $hex
            ));
        }

        $ehex = ltrim($hex, '#');

        if (strlen($ehex) === 3) {
            $ehex = $ehex[0] . $ehex[0] .
                    $ehex[1] . $ehex[1] .
                    $ehex[2] . $ehex[2];
        }

        $color = array_map('hexdec', str_split($ehex, 2));

        return $this->setRed($color[0])
                        ->setGreen($color[1])
                        ->setBlue($color[2])
                        ->setAlpha($alpha);
    }
1008381
public static function str_to_hex($string) {
        $hex = '';

        for ($i = 0; $i < strlen($string); $i++) {
            $hex .= dechex(ord($string[$i]));
        }

        return $hex;
    }
976573
public static function fromHexString($color)
    {
        $color = rtrim($color, '#');
        preg_match_all('([0-9a-f][0-9a-f])', $color, $rgb);

        $c = new self();
        list($c->r, $c->g, $c->b) = array_map('hexdec', $rgb[0]);

        return $c;
    }
1138396
public function encodeBase58($hex)
    {
        $this->preOpMethodParamsCheck(array($hex));

        try {

            if (strlen($hex) % 2 != 0 || $this->Test($hex) != 'hex') {
                throw new \Exception('Uneven number of hex characters or invalid parameter passed to encodeBase58 function.  Value received was "' . var_export($hex, true) . '".');
            } else {
                $orighex = $hex;
                $hex     = $this->addHexPrefix($this->prepAndClean($hex));
                $return  = strrev($this->encodeValue($hex, '58'));

                for ($i = 0; $i < strlen($orighex) && substr($orighex, $i, 2) == '00'; $i += 2) {
                    $return = '1' . $return;
                }
            }

            return $return;

        } catch (\Exception $e) {
            throw $e;
        }
    }
1196725
public static function IPv6Hex2Bin($hex) {
			// use PHP-function if PHP was compiled with IPv6-support
		if (defined('AF_INET6')) {
			$bin = inet_pton($hex);
		} else {
			$hex = self::normalizeIPv6($hex);
			$hex = str_replace(':', '', $hex); // Replace colon to nothing
			$bin = pack("H*" , $hex);
		}
		return $bin;
	}
941930
private function _str2hex($string)
    {
        $hex = bin2hex($string);
        $xhex = "";

        for ($i = 0; $i < strlen($hex) - 1; $i += 2) {
            $xhex .= '\x' . $hex[$i] . $hex[$i + 1];
        }

        return $xhex;
    }
259176
public static Color fromHex( String hex ) {
        if (hex.startsWith("#")) {
            hex = hex.substring(1);
        }
        int length = hex.length();
        int total = 6;
        if (length < total) {
            // we have a shortened version
            String token = hex;
            int tokenLength = token.length();
            for( int i = 0; i < total; i = i + tokenLength ) {
                hex += token;
            }
        }

        int index = 0;
        String r = hex.substring(index, index + 2);
        String g = hex.substring(index + 2, index + 4);
        String b = hex.substring(index + 4, index + total);
        return new Color(Integer.valueOf(r, 16), Integer.valueOf(g, 16), Integer.valueOf(b, 16));
    }
895064
public static function fromHex($hex)
  {
    if(strlen($hex) != 2)
    {
      throw new Exception("given parameter '" . $hex . "' is not a valid hexadecimal number");
    }

    return new self(chr(hexdec($hex)));
  }
623734
private function _get_hue( $hex ) {
		$red   = hexdec( substr( $hex, 0, 2 ) );
		$green = hexdec( substr( $hex, 2, 2 ) );
		$blue  = hexdec( substr( $hex, 4, 2 ) );
		$max_rgb = max( $red, $green, $blue );
		$min_rgb = min( $red, $green, $blue );

		if ( $red === $green && $red === $blue ) {
			return 0;
		}

		$diff_max_min_rgb = $max_rgb - $min_rgb;

		if ( $red === $max_rgb ) {
			$hue = 60 * ( $diff_max_min_rgb ? ( $green - $blue ) / $diff_max_min_rgb : 0 );
		} elseif ( $green === $max_rgb ) {
			$hue = 60 * ( $diff_max_min_rgb ? ( $blue - $red ) / $diff_max_min_rgb : 0 ) + 120;
		} elseif ( $blue === $max_rgb ) {
			$hue = 60 * ( $diff_max_min_rgb ? ( $red - $green ) / $diff_max_min_rgb : 0 ) + 240;
		}

		if ( 0 > $hue ) {
			$hue += 360;
		}

		return $hue;
	}
12368
public function getHex($prefix = '')
    {
        return sprintf('%s%02x%02x%02x', $prefix, $this->r, $this->g, $this->b);
    }
777646
protected function decodePropValue($hex, $string = false)
    {
        $decodePropValue = '';

        $blobs = str_split($hex, 6);

        foreach ($blobs as $blob) {
            $bin = decbin(hexdec($blob));

            $controlY = substr($bin, 4, 6);
            $nibbleY = substr($bin, 10, 4);
            $controlX = substr($bin, 14, 6);
            $nibbleX = substr($bin, 20, 4);

            $byte = $this->nibbleControl($nibbleX, $controlX).$this->nibbleControl($nibbleY, $controlY);

            if ($string) {
                $decodePropValue .= MbString::chr(bindec($byte));
            } else {
                $decodePropValue = $this->dec2hex(bindec($byte)).$decodePropValue;
            }
        }

        return $decodePropValue;
    }
39148
private function formatHex(string $hex): string
    {
        $hex = str_pad($hex, 32, '0');
        preg_match('/([a-f0-9]{8})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{12})/', $hex, $matches);
        array_shift($matches);
        $expandedUUID = implode('-', $matches);

        return $expandedUUID;
    }
197383
public function hex2bin($hex)
    {
        $binLen = ceil(mb_strlen($hex) / 2);

        // size validation while creating
        $buffer = Buffer::fromHex($hex, $binLen);
        return $buffer->getBinary();
    }
882020
public function fromHex($hex)
    {
        $this->values = array(
            'red' => hexdec($hex[0] . $hex[1]),
            'green' => hexdec($hex[2] . $hex[3]),
            'blue' => hexdec($hex[4] . $hex[5])
        );
    }
263682
public function littleEndian($hex)
    {
        $result = '';

        for ($x = strlen($hex) - 2; $x >= 0; $x = $x - 2) {
            $result .= substr($hex, $x, 2);
        }

        return $result;
    }