JCL Help:CountBitsSet@Byte

From Project JEDI Wiki
Jump to navigationJump to search


Summary

Returns the number of set bits in the passed value.


Pascal

 function CountBitsSet(X: Byte): Integer; overload;
function CountBitsSet(X: Word): Integer; overload;
function CountBitsSet(X: Smallint): Integer; overload;
function CountBitsSet(X: ShortInt): Integer; overload;
function CountBitsSet(X: Integer): Integer; overload;
function CountBitsSet(X: Cardinal): Integer; overload;
function CountBitsSet(X: Int64): Integer; overload;
function CountBitsSet(P: Pointer; Count: Cardinal): Cardinal; overload;


Parameters

Parameters Description
X: Byte The value for which to determine the number of bits that are set.


Return Value

The number of set bits or 0 if no bits are set.


Description

CountBitsSet returns the number of bits that are set (value 1) in the binary representation of the supplied Value. For example, CountBitsSet(1) returns 1, CountBitsSet(3) returns 2 etc. Note that signed integers are stored in two's complement form and therefore, for example, CountBitsSet(-1) will return 32!


See Also

BitsLowest BitsHighest


About

Unit

JclLogic


Donator

Michael Schnell


Contribute to this help topic

This documentation wiki is based on the collaborative effort of Project JEDI users. Your edits are welcome in order to improve documentation quality: edit this page