Page 1 of 1
Bitwise AND
Posted: Sat Sep 25, 2021 12:46 am
by daniel_dlds
Hi,
I am trying to convert a 16 bit integer to two 8bit numbers.
I tried : LET vh=65280 AND value : LET vl=255 AND value
I am getting it wrong I think. I checked the ZX BASIC manual and seems like AND is not for this purpose.
vh is giving me 2 when I use 2 as the value variable.
How do I do this ? Are there any bitwise and operators ?
Thanks
Re: Bitwise AND
Posted: Sat Sep 25, 2021 12:09 pm
by zx-heinz
daniel_dlds wrote: ↑Sat Sep 25, 2021 12:46 am
Hi,
I am trying to convert a 16 bit integer to two 8bit numbers.
I tried : LET vh=65280 AND value : LET vl=255 AND value
I am getting it wrong I think. I checked the ZX BASIC manual and seems like AND is not for this purpose.
vh is giving me 2 when I use 2 as the value variable.
How do I do this ? Are there any bitwise and operators ?
Thanks
EDIT Sept,29th: Sorry for mistake!! Here is the correction:
Hi,
you should use:
LET vh=INT( value/256): LET vl=value-256*vh
The Sinclair BASIC doesn't contain any bitwise AND. There is only a possibility to convert binary numbers into decimal ones by LET x=BIN 0111 e.g., but even for the inverse oparation decimal->binary there is no predefined command.
Re: Bitwise AND
Posted: Sat Sep 25, 2021 7:48 pm
by 1024MAK
On a ZX Spectrum the logical operators AND, OR and NOT treat any non zero number as true. They are
not bitewise.
Note that these logical operators don’t necessarily return 1 for true, sometimes they return one of the arguments.
Here is a ZX81 program showing how they work. It’s similar for the ZX Spectrum.
Mark