## Bitwise AND

daniel_dlds
Posts: 15
Joined: Tue Dec 10, 2019 12:17 am
Contact:

### Bitwise AND

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: 41
Joined: Thu Apr 27, 2017 8:56 pm

### Re: Bitwise AND

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.
1024MAK
Posts: 5261
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

### Re: Bitwise AND

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
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp