note 108599 added to function.unpack
| From: | kobrasrealm at gmail dot com | Date: | Wed, 09 May 2012 17:50:15 +0000 |
| Subject: | note 108599 added to function.unpack | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187555@lists.php.net to get a copy of this message | ||
I wrote a quick pair of functions using pack/unpack for converting between raw binary (e.g.
openssl_random_pseudo_bytes() output) and hexadecimal (e.g. hash() output):
<?php
function raw2hex($raw) {
$m = unpack('H*', $raw);
return $m[1];
}
function hex2raw($hex) {
return pack('H*', $hex);
}
?>
Feel free to suggest any improvements, but I thought this was worth sharing.
----
Server IP: 69.147.83.197
Probable Submitter: 132.170.82.64
----
Manual Page -- http://www.php.net/manual/en/function.unpack.php
Edit -- https://master.php.net/note/edit/108599
Del: integrated -- https://master.php.net/note/delete/108599/integrated
Del: useless -- https://master.php.net/note/delete/108599/useless
Del: bad code -- https://master.php.net/note/delete/108599/bad+code
Del: spam -- https://master.php.net/note/delete/108599/spam
Del: non-english -- https://master.php.net/note/delete/108599/non-english
Del: in docs -- https://master.php.net/note/delete/108599/in+docs
Del: other reasons-- https://master.php.net/note/delete/108599
Reject -- https://master.php.net/note/reject/108599
Search -- https://master.php.net/manage/user-notes.php