note 42617 added to function.intval

From: Date: Mon, 24 May 2004 00:38:50 +0000
Subject: note 42617 added to function.intval
Groups: php.notes 
Request: Send a blank email to php-notes+get-70007@lists.php.net to get a copy of this message
When trying to read 32bit values (32 bit limitation depends on the word size of your machine) from a string that is represented in hex with the high bit set, eg. F9833234 intval returns -1. The reason is the sign bit being set. This number is larger than can be saved in a signed int. The way around this is to read the value in using two calls to intval. eg. $val = intval(substr($str,0,4), 16); // read high 16 bit word $val <<= 16; // shift hi word correct position $val |= intval(substr($str, 4, 4), 16); // read low 16 bit word ---- Manual Page -- http://www.php.net/manual/en/function.intval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42617 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42617&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42617&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70007) next »