Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread BYTE FIELD SET/GET BIT (16 flags)
Thu, Jul 4 2024 2:50 AMPermanent Link

Andrew Hill

I have a Table with a Map Field (2 bytes=16positions):= "Map" BYTE(8) DEFAULT X'0000000000000000' (this will hold 16 flags which can be viewed/set as either 1 or 0)

How do I test for position 15 X'nnnnnnnnnnnnnn1n' to see if it is = 1 in a SELECT statement ?

How do I UPDATE MyTable SET Map = X'nnnnnnnnnnnnnn1n' position 15 to 1 without affecting the others ?

Please advise - Thanks
Thu, Jul 4 2024 7:00 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Andrew,

BYTE(8) is 8 bytes = 64 bits, not 16.

Anyway, about your question:
It's possible, but not efficient. The only way I can think of to do this is to define a UDF implemented in an external module (dll) and use binary masks to test/set values.
Using only SQL I am not aware of any way to execute bit level operations (and it would defeat the basic principles of relational databases anyway).

--
Fernando Dias
[Team Elevate]
Fri, Jul 5 2024 6:34 PMPermanent Link

Andrew Hill

Yes but I was referring to 16 possible states of 1 or 0
Fri, Jul 5 2024 6:35 PMPermanent Link

Andrew Hill

Visually seeing the 16 flag states as well
Sun, Jul 7 2024 12:04 AMPermanent Link

Andrew Hill

Want 16 flags, trying BYTE for speed, could do STRING instead but prefer BYTES

Please show how to Read Bit from Byte, and then set Bit in Byte.
Image