note 110225 added to function.dechex

From: Date: Wed, 03 Oct 2012 01:02:37 +0000
Subject: note 110225 added to function.dechex
Groups: php.notes 
Request: Send a blank email to php-notes+get-191102@lists.php.net to get a copy of this message
I wrote this to convert hex into signed int, hope this helps someone out there... peace :) $hex = dechex(-32767); $dec = shexdex($hex); function shexdex($hex){ $dec = hexdec($hex); // Negative number (in binary if the msb is 1 then it is neg) // since one hex is 4bits, the value 8 and up contain msb of 1, hence negative number if ($hex[0] >= '8'){ // Note: if you use the digit 8 it is not the same as '8' $dec -= 1; $dec = ~$dec; return -$dec; } return $dec; } if ($dec == -32767){ echo 'Yay!'; } ---- Server IP: 69.147.83.199 Probable Submitter: 24.212.146.29 ---- Manual Page -- http://www.php.net/manual/en/function.dechex.php Edit -- https://master.php.net/note/edit/110225 Del: integrated -- https://master.php.net/note/delete/110225/integrated Del: useless -- https://master.php.net/note/delete/110225/useless Del: bad code -- https://master.php.net/note/delete/110225/bad+code Del: spam -- https://master.php.net/note/delete/110225/spam Del: non-english -- https://master.php.net/note/delete/110225/non-english Del: in docs -- https://master.php.net/note/delete/110225/in+docs Del: other reasons-- https://master.php.net/note/delete/110225 Reject -- https://master.php.net/note/reject/110225 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191102) next »