php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #13532 bit_count()
Submitted: 2001-10-03 13:10 UTC Modified: 2001-10-03 14:16 UTC
From: russlndr at online dot no Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: russlndr at online dot no
New email:
PHP Version: OS:

 

 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-03 13:12 UTC] derick@php.net
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.

Derick
 [2001-10-03 14:16 UTC] rasmus@php.net
I 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)));
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 15:01:30 2025 UTC