Bitwise AND

Post Reply
daniel_dlds
Posts: 13
Joined: Tue Dec 10, 2019 12:17 am
Contact:

Bitwise AND

Post 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
zx-heinz
Posts: 36
Joined: Thu Apr 27, 2017 8:56 pm

Re: Bitwise AND

Post 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.
Last edited by zx-heinz on Tue Sep 28, 2021 7:07 pm, edited 1 time in total.
User avatar
1024MAK
Posts: 3824
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Bitwise AND

Post 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.
E3670189-997E-4DC1-9ED4-F14A061130D0.jpeg
6B49D0F2-CF85-47D2-AC0C-420B628BFDBA.jpeg
Mark
Post Reply