Page 1 of 1

bitwise operators

Posted: Mon Apr 11, 2016 9:25 pm
by flinx
Hello.

I've neglected the QL for too many years, and now I'm lost. (Also, I'm old and don't speak English very well: a very bad combo).

Enter 'The Question': I remember that in SuperBasic exists bitwise operators: && (AND) ^^ (XOR) and || (OR). But there is, in SuperBasic, the equivalent bitwise operator for NOT (~~)?

If I try

PRINT ~~value1 (edited, this is the correct form - in C - for bitwise not)

the result is a parser error (bad line).

Bitwise NOT can be implemented via SuperBasic extension, obviously. But I try to not reinvent the wheel.

Someone can help? Thanks in advance.

Emiliano (a.k.a. Flinx)

Re: bitwise operators

Posted: Mon Apr 11, 2016 10:34 pm
by tofro
You were close:

NOT is the "logical" NOT operator
~ (single tilde) is the "binary" NOT operator (according to the QPC concepts guide, and that is wrong)
~~ is the right one....

Tobias

Re: bitwise operators

Posted: Mon Apr 11, 2016 10:37 pm
by ppe
Hi Emiliano,

just tested on my JS ROM. Tried this:

Code: Select all

PRINT ~~12
and got the answer -13

So, the classic non-helpful "works on my machine" answer.... :)

Best regards,
Petri

Re: bitwise operators

Posted: Mon Apr 11, 2016 10:46 pm
by tofro
Apparently, bitwise operators work on integer variables only in the original QDOS.

SMSQ/E accepts floating point numbers (and converts them to 32-bit longs before applying the operator)

So working/non working can very well depend on the value you tried.

Tobias

Re: bitwise operators

Posted: Mon Apr 11, 2016 10:56 pm
by flinx
Many thanks to you all. The error was mine, and very stupid: I use Q-emulator, and to input the tilde char I was typing ALT+5 combination . I don't know why, but that does not work. If I copy the tilde from PETRI example: voilĂ , it works.

Ok, time to resume my old QL ... :-)

Again, thanks to all.

Emiliano