note 110973 modified in function.hex2bin by danbrown

From: Date: Thu, 17 Jan 2013 15:27:27 +0000
Subject: note 110973 modified in function.hex2bin by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193148@lists.php.net to get a copy of this message
For those who have php version prior to 5.4, i have a solution to convert hex to binary. It works for me in an encryption and decryption application. <?php function hextobin($hexstr) { $n = strlen($hexstr); $sbin=""; $i=0; while($i<$n) { $a =substr($hexstr,$i,2); $c = pack("H*",$a); if ($i==0){$sbin=$c;} else {$sbin.=$c;} $i+=2; } return $sbin; } ?> --was-- For those who have php version prior to 5.4, i have a solution to convert hex to binary. Combining the comments from below. It works for me in an encryption and decryption application. function hextobin($hexstr) { $n = strlen($hexstr); $sbin=""; $i=0; while($i<$n) { $a =substr($hexstr,$i,2); $c = pack("H*",$a); if ($i==0){$sbin=$c;} else {$sbin.=$c;} $i+=2; } return $sbin; } http://php.net/manual/en/function.hex2bin.php

« previous php.notes (#193148) next »