NOTÍCIA

Converter uma string em hex para binário

Com o código abaixo você
poderá converter rapidamente uma string em hex
para binário. E nem se preocupe em usar a pack,
esta função abaixo é bem mais simples.

<?PHP

// Function Hex2Bin
// By Roberto Bertó <berto@que.com.br> under GPL
license.
// Free like Linux!

// converts a string in hex to a bin string
    function hex2bin ($s) {

        $n = strlen($s);

        if ($n % 2 != 0) { return; }

        for ($x = 1; $x <= $n/2; $x++) {

            $t .= chr(hexdec(substr($s,2* $x - 2,2)));

        }
        return $t;

    }
?>

Matérias especiais e reportagens conduzidas internamente pela Redação iMasters. Acompanhe no Twitter @imasters e no Instagram/Threads @portalimasters

Mais de Redação iMasters
Ver perfil →