Hello,
I refer to https://ugbasic.iwashere.eu/manual/datatypes, especially the text:
x = y HAS BIT 4 : ' this is like y AND 32
x = y HAS NOT BIT 4 : ' this is like y AND 239
x = BIT 4 OF y : ' this is like y AND 32
it seems to me that the second line is somewhat wrong in the comment. I would think that this stands for "y and 223" (239 is 255-16, not -32)? Semantics would then be that this one bit is not set? Or should it mean that all the other bits are set? This is not so well described, I must say. It looks from this formula that all the other bits are meant to be set, no matter whether bit 4 is set or not. Is that correct?
Description of bit type a bit unclear
-
- Site Admin
- Posts: 204
- Joined: Fri Oct 06, 2023 8:25 pm
Re: Description of bit type a bit unclear
Hi Hrundy and welcome!
At this point I ask for confirmation to fix the behavior.
Thank you again!

I think you are right about the comment, but not on the value, that seems not exact. Infact, the HAS NOT BIT instruction will check a bit off (0) by checking the state of a specific bit inside the given data. The bit position is zero based, and starts from the less significative bit and go on. In implementation terms, the instruction is like NOT( x HAS BIT n). Since x HAS BIT n can be expressed as x AND 2^n, and NOT( a AND b) can be expressed as a AND NOT b. So, when we are talking about BYTE data type:
Code: Select all
x = y HAS NOT BIT 4
x = NOT (y HAS BIT 4)
x = NOT (y AND 2^4)
x = NOT (y AND 16)
x = y AND NOT %00010000
x = y AND %11101111
x = y AND 239
The desired semantics would be to test that a bit is zero. Honestly, since you pointed this out to me, I'm not so sure that it's computed correctly. We should do some test cases to see that.
You are absolutely right about this. At the moment the current implementation, which I repeat I do not know if it is completely correct, is the one I illustrated above. Since the semantics should be to test that a bit is zero, in reality I believe that the correct function is:
Code: Select all
x = (y AND 2^n) = 0
Thank you again!