note 108024 added to function.dechex

From: Date: Fri, 23 Mar 2012 07:09:52 +0000
Subject: note 108024 added to function.dechex
Groups: php.notes 
Request: Send a blank email to php-notes+get-186781@lists.php.net to get a copy of this message
If you want to create or parse signed Hex values: <?php // $d should be an int function sdechex($d) { return ($d<0) ? ('-' . dechex(-$d)) : dechex($d); } // $h should be a string function shexdec($h) { return ($h[0] === '-') ? -('0x' . substr($h,1) + 0) : ('0x' . $h + 0); } // test $v = sdechex(-123); // string(3) "-7b" $i = shexdec($v); // int(-123) var_dump($v, $i); ?> Also note that ('0x' . $str + 0) is faster than hexdec() ---- Server IP: 69.147.83.197 Probable Submitter: 99.243.44.37 ---- Manual Page -- http://www.php.net/manual/en/function.dechex.php Edit -- https://master.php.net/note/edit/108024 Del: integrated -- https://master.php.net/note/delete/108024/integrated Del: useless -- https://master.php.net/note/delete/108024/useless Del: bad code -- https://master.php.net/note/delete/108024/bad+code Del: spam -- https://master.php.net/note/delete/108024/spam Del: non-english -- https://master.php.net/note/delete/108024/non-english Del: in docs -- https://master.php.net/note/delete/108024/in+docs Del: other reasons-- https://master.php.net/note/delete/108024 Reject -- https://master.php.net/note/reject/108024 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186781) next »