BitsSet Function
Returns a number from 0 -> 32 indicating the number of Bits Set.

Unit
QESBPCSSystem

Declaration
Function BitsSet(const BitList: TESBLongBitList): Byte;

Description
This is also known as the Hamming Weight. Can pass both types of BitList to this.

Parameters
BitList BitList to process.

Category
Memory Operations

Implementation

function BitsSet (const BitList: TESBLongBitList): Byte;
asm
        mov edx, eax	// EDX <- BitList
        xor eax, eax	// Clear EAX
@@Loop: add edx, edx	// "Shift Left"
	                    // if no carry then no increment
        adc eax, 0   	// Otherwise Inc EAX (which is the function Result)
        and edx, edx
	jnz @@Loop  		// Loop for all Bits in BitList
End;


HTML generated by Time2HELP
http://www.time2help.com