AND / OR of Numeric Values?

Anything QL Software or Programming Related.
Post Reply
User avatar
t0nyt
Aurora
Posts: 984
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

AND / OR of Numeric Values?

Post by t0nyt »

I'm trying to convert my I2C code from BBC BASIC to QL BASIC, but have hit a problem (there's probably others!)

I need to AND and OR numeric values, but in QL BASIC AND, for instance, is a comparison so always returns 1 (or 0 I guess)

Is there anyway in QL Basic to perform arithmetic AND/OR please?

e.g. L=((C*16) AND 250) OR 9, just returns 1 regardless of the value of C

Has been a long time since I used BASIC for anything other than basic stuff

Many thanks


User avatar
tofro
Font of All Knowledge
Posts: 3108
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: AND / OR of Numeric Values?

Post by tofro »

SuperBASIC has specific boolean operators

&& for AND
|| for OR
^^for XOR

The logical operators do not operate bit-wise, but consider everything that evaluates to "0" as FALSE, and everything else as TRUE.
Last edited by tofro on Sun May 18, 2025 7:40 pm, edited 1 time in total.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
t0nyt
Aurora
Posts: 984
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: AND / OR of Numeric Values?

Post by t0nyt »

tofro wrote: Sun May 18, 2025 7:38 pm SuperBASIC has specific boolean operators

&& for AND
|| for OR
^^for XOR
Many thanks!


User avatar
ql_freak
Gold Card
Posts: 498
Joined: Sun Jan 18, 2015 1:29 am

Re: AND / OR of Numeric Values?

Post by ql_freak »

For operators (IMHO work all also with the Artithmetic Stack [RI-stack] not just in SuperBASIC) see the "Concepts" section of the QL User Guide "Operators".

p.s.: AFAIK == compares strings case independently (that not documented in the User Guide, at least not in the English one).


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
Post Reply