[Overview][Types][Procedures and functions][Index] |
Count bits set
Source position: bitmanip.pas line 65
function CountBits( |
v: Byte |
):PtrUInt; |
v: Word |
):PtrUInt; |
v: LongWord |
):PtrUInt; |
v: QWord |
):PtrUInt; |
v |
|
Input value |
v |
|
Input value |
v |
|
Input value |
v |
|
Input value |
Returns the count of bits set in v.
var value: Byte; c: PtrUInt; begin value := 5; // bits set c := CountBits(value); // c is now 2 // bits not set c := CountBits(not value); // c is now 6 end.
The used algorith is taken from Bit Twiddling Hacks