note 71795 added to function.dechex

From: Date: Sat, 16 Dec 2006 07:33:16 +0000
Subject: note 71795 added to function.dechex
Groups: php.notes 
Request: Send a blank email to php-notes+get-120650@lists.php.net to get a copy of this message
Be very careful calling dechex on a number if it's stored in a string. For instance: The max number it can handle is 4294967295 which in hex is FFFFFFFF, as it says in the documentation. dechex(4294967295) => FFFFFFFF //CORRECT BUT, if you call it on a string of a number, it casts to int, and automatically gives you the largest int it can handle. dechex('4294967295') => 7FFFFFFF //WRONG! so you'll need to cast to a float: dechex((float) '4294967295') => FFFFFFFF //CORRECT This took me FOREVER to figure out, so hopefully I just saved someone some time. ---- Server IP: 66.163.161.117 Probable Submitter: 76.168.144.220 ---- Manual Page -- http://www.php.net/manual/en/function.dechex.php Edit -- https://master.php.net/note/edit/71795 Del: integrated -- https://master.php.net/note/delete/71795/integrated Del: useless -- https://master.php.net/note/delete/71795/useless Del: bad code -- https://master.php.net/note/delete/71795/bad+code Del: spam -- https://master.php.net/note/delete/71795/spam Del: non-english -- https://master.php.net/note/delete/71795/non-english Del: in docs -- https://master.php.net/note/delete/71795/in+docs Del: other reasons-- https://master.php.net/note/delete/71795 Reject -- https://master.php.net/note/reject/71795 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120650) next »