note 85297 added to function.decbin

From: Date: Sun, 24 Aug 2008 13:25:15 +0000
Subject: note 85297 added to function.decbin
Groups: php.notes 
Request: Send a blank email to php-notes+get-143791@lists.php.net to get a copy of this message
Careful trying binary-wise tests with integers: # FFFFFFFF command: php -r 'print(decbin(4294967295)."\n");' result: 11111111111111111111111111111111 # C3E9CAC8 command: php -r 'print(decbin(3286878920)."\n");' result: 11000011111010011100101011001000 # regardless of specifying "(int)", using bitwise AND: command: php -r 'print((int)(3286878920 & 4294967295)."\n");' result: -1008088376 (int) # now the expected result will happen (guess the performance impact) command: php -r 'print(bindec(decbin((3286878920 & 4294967295)))."\n");' result: 3286878920 (float) additional note: if you "bitwise and" some random bits with a sequence of 1-bit of the same length, the expected result is the same "random bits sequence" unchanged. If you want to keep this in the integer world for faster comparisons, you risk messing your result for the signed integer size limitation. The maximum value you can use for the desired result is (7FFFFFFF -- or integer 2147483647), half of the maximum 'unsigned' integer 32-bit(platform-dependent) value. ---- Server IP: 69.147.83.197 Probable Submitter: 201.58.215.165 ---- Manual Page -- http://www.php.net/manual/en/function.decbin.php Edit -- https://master.php.net/note/edit/85297 Del: integrated -- https://master.php.net/note/delete/85297/integrated Del: useless -- https://master.php.net/note/delete/85297/useless Del: bad code -- https://master.php.net/note/delete/85297/bad+code Del: spam -- https://master.php.net/note/delete/85297/spam Del: non-english -- https://master.php.net/note/delete/85297/non-english Del: in docs -- https://master.php.net/note/delete/85297/in+docs Del: other reasons-- https://master.php.net/note/delete/85297 Reject -- https://master.php.net/note/reject/85297 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143791) next »