Count the total number of bits set in the supplied buffer, taken to be of the supplied size.
| Return Type | Function name | Arguments |
|---|---|---|
| uint32_t | CountBits | (const void*,uint32_t,) |
Declared in file: hzIntset.h
Defined in file : hzIntset.cpp
Function Logic:
Function body:
uint32_t CountBits (const void* buf)uint32_t nBytes,
{
// Category: Bitwise
//
// Count the total number of bits set in the supplied buffer, taken to be of the supplied size.
//
// Arguments: 1) buf The const void* buffer
// 2) nBytes The number of bytes
//
// Returns: Number of bits found to be set
const uchar* uber ; // Buffer as a series of chars
uint32_t nCount ; // Buffer iterator
uint32_t nBits ; // Cumulative bit counter
if (!buf)
return -1;
uber = (uchar*) buf ;
for (nBits = nCount = 0; nCount < nBytes ; nCount++)
nBits += s_BitArray[uber[nCount]] ;
return nBits ;
}