[Overview][Types][Procedures and functions][Index] Reference for unit 'bitmanip' (#pascalio)

CountBits

Count bits set

Declaration

Source position: bitmanip.pas line 65

function CountBits(

  v: Byte

):PtrUInt;

function CountBits(

  v: Word

):PtrUInt;

function CountBits(

  v: LongWord

):PtrUInt;

function CountBits(

  v: QWord

):PtrUInt;

Arguments

v

  

Input value

Arguments

v

  

Input value

Arguments

v

  

Input value

Arguments

v

  

Input value

Description

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


Documentation generated on: 2020-05-22