note 66374 added to function.pack

From: Date: Sat, 20 May 2006 11:44:18 +0000
Subject: note 66374 added to function.pack
Groups: php.notes 
Request: Send a blank email to php-notes+get-111733@lists.php.net to get a copy of this message
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? ---- Server IP: 129.16.214.50 Probable Submitter: 85.226.123.107 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.pack.php Edit -- http://master.php.net/note/edit/66374 Del: integrated -- http://master.php.net/note/delete/66374/integrated Del: useless -- http://master.php.net/note/delete/66374/useless Del: bad code -- http://master.php.net/note/delete/66374/bad+code Del: spam -- http://master.php.net/note/delete/66374/spam Del: non-english -- http://master.php.net/note/delete/66374/non-english Del: in docs -- http://master.php.net/note/delete/66374/in+docs Del: other reasons-- http://master.php.net/note/delete/66374 Reject -- http://master.php.net/note/reject/66374 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111733) next »