Test for bit set in integer value

Slawek_GuzekSlawek_Guzek Member Posts: 1,690
edited 2006-03-19 in NAV Tips & Tricks
Do you need to know if some bit is set in some integer value ?

I didn't manage to find simple binary AND operator, so had to write this test in a little more complicated way :)

testForBit(BitNo : Integer;Value : Integer) : Boolean
// test if bit BitNo is set in word Value
IF (BitNo >=0) AND (BitNo < 32) THEN
EXIT( POWER(2,BitNo) <= (Value MOD POWER(2,BitNo+1)) );


Enjoy,
Slawek Guzek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.