note 66374 deleted from function.pack by nlopess

From: Date: Sat, 20 May 2006 12:30:47 +0000
Subject: note 66374 deleted from function.pack by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-111734@lists.php.net to get a copy of this message
Note Submitter: ---- I'm sitting here dumbstruck. There must be a simple strait forward way of doing this! I want to convert a hex string to byte values. 1a23c7 -> {26, 35, 199} After fooling around with unpack for a while, I surrendered and wrote this: function parseHex($hex) { $n = strlen($hex); for($i = 0; $i < $n; ) { $a = ord($hex[$i++]); $a = $a > 60 ? $a - 87 : $a - 48; $b = ord($hex[$i++]); $b = $b > 60 ? $b - 87 : $b - 48; $bytes[] = $a*16 + $b; } return $bytes; } But I'm missing something some ware, right? How are you supposed to do this conversion PHP style?

« previous php.notes (#111734) next »