JCL Help:TestBit@Byte@TBitRange

From Project JEDI Wiki
Jump to navigationJump to search


Summary

Tests a bit in an integer-type value.


Pascal

 function TestBit(const Value: Byte; const Bit: TBitRange): Boolean; overload;
function TestBit(const Value: Shortint; const Bit: TBitRange): Boolean; overload;
function TestBit(const Value: Smallint; const Bit: TBitRange): Boolean; overload;
function TestBit(const Value: Word; const Bit: TBitRange): Boolean; overload;
function TestBit(const Value: Cardinal; const Bit: TBitRange): Boolean; overload;
function TestBit(const Value: Integer; const Bit: TBitRange): Boolean; overload;
function TestBit(const Value: Int64; const Bit: TBitRange): Boolean; overload;


Parameters

Parameters Description
const Value: Byte The integer-typed variable for which to test a bit.
const Bit: TBitRange The 0 based bit position of the bit to test. This is a modulo N bit position where N is the number of bits in the Value parameter. For example, if Value is a Byte then Bit position is interpreted as Bit mod 8. Warning: When calling this function you must cast a value passed to this parameter to a TBitRange as in: "TestBit(Value, TBitRange(1))" otherwise Delphi will incorrectly use the TestBit(Byte, TBitRange) overload instead of the correct overload. This is a known problem in the compiler, not an error in the JCL.


Return Value

True if the bit at the specified position is set, False if it is cleared.


Description

TestBit tests the specified bit position of the passed integer typed variable. In other words if the bit at the specified position is 1 then the function returns True, if it is 0 the function returns False.


See Also

TestBits ClearBit ToggleBit SetBit


About

Unit

JclLogic


Donator

Marcel van Brakel


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