Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 15 total
Thread Test a bit in an integer field in a filter??
Thu, Jul 22 2021 5:55 PMPermanent Link

Ian Branch

Avatar

Hi Team,
I have an integer field where each bit means something.
How can I test a bit in the integer value/field in a filter?

Regards & TIA,
Ian
Thu, Jul 22 2021 11:09 PMPermanent Link

Raul

Team Elevate Team Elevate

On 7/22/2021 5:55 PM, Ian Branch wrote:
> Hi Team,
> I have an integer field where each bit means something.
> How can I test a bit in the integer value/field in a filter?

Have not tested in filter but divide by the value corresponding to bit
position (power of 2 basically) and then use MOD 2 to see if last bit is
1. use floor to ensure int values.

Basically

Value mod 2 = 1 if last bit is set
(floor(value/2)) mod 2=1 for 2nd last
(floor(value/4)) mod 2=1 for 3nd last etc


Raul







Fri, Jul 23 2021 12:57 AMPermanent Link

Ian Branch

Avatar

Thanks Raul.  Messy when testing several bits but it works.  Wink
I have asked Tim to consider a BitTest() function in Filtering..  i.e. BitTest(fieldName, bit)  return true or false of set or not.

Regards & Tks again,
Ian
Fri, Jul 23 2021 2:27 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Raul


Wow - colour me impressed

Roy Lambert
Fri, Jul 23 2021 2:27 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


To build on Raul's post - why not set up computed (or generated) columns to represent each bit. Should make accessing easier

Roy Lambert
Fri, Jul 23 2021 2:40 AMPermanent Link

Ian Branch

Avatar

Show off.  Wink
Fri, Jul 23 2021 3:19 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


Yeah - but I'm pretty with it

Roy Lambert (posting as a compulsive liar)
Fri, Jul 23 2021 2:47 PMPermanent Link

Terry Swiers

> To build on Raul's post - why not set up computed (or generated) columns to represent each bit. Should make accessing easier

Or create your own function in the schema...

CREATE FUNCTION "IsBitSet" (IN "Value" INTEGER, IN "BitPos" SMALLINT)
RETURNS BOOLEAN
BEGIN
DECLARE lValue INTEGER;
DECLARE Result Boolean default False;
IF (BitPos >= 0) and (BitPos <= 31) THEN
 SET lValue = FLOOR(Value/POWER(2, BitPos));
 SET Result = lValue mod 2 = 1;
END IF;
Return Result;
END
VERSION 1.00
Fri, Jul 23 2021 4:40 PMPermanent Link

Ian Branch

Avatar

Hi Terry,
Interesting thought.
How would I use that in an EDBTable filter?

Regards,
Ian

(P.S.  I have filed that little bit of code away for future reference.)
Fri, Jul 23 2021 6:16 PMPermanent Link

Terry Swiers


> How would I use that in an EDBTable filter?

Just like any other filter condition.  If you are filtering on the column "ABC"...

Table.Filter := 'IsBitSet(ABC, 0)'
Table.Filtered := True;
Page 1 of 2Next Page »
Jump to Page:  1 2
Image