|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-10-03 13:10 UTC] russlndr at online dot no
Suggestion: Add a function who can count number of bits who are set in a variable. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 01:00:01 2025 UTC |
function bit_count($var) { return strlen($var) * 8; } It's very easy to do in PHP itself, thus I see no use for this function. DerickI think he may have meant the number of bits set in a bit field. Something like this should cover it: function bit_count($num) { return strlen(str_replace('0','',decbin($num))); }