bitwise operators

Anything QL Software or Programming Related.
Post Reply
flinx
ROM Dongle
Posts: 5
Joined: Sun Apr 10, 2016 8:53 pm

bitwise operators

Post 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)


I'm an old boy from Italy. Please be kind with my spelling ;)
User avatar
tofro
Font of All Knowledge
Posts: 3112
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: bitwise operators

Post 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
Last edited by tofro on Mon Apr 11, 2016 10:42 pm, edited 1 time in total.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: bitwise operators

Post 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


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

Re: bitwise operators

Post 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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
flinx
ROM Dongle
Posts: 5
Joined: Sun Apr 10, 2016 8:53 pm

Re: bitwise operators

Post 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


I'm an old boy from Italy. Please be kind with my spelling ;)
Post Reply