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
Bitwise AND
-
- Posts: 17
- Joined: Tue Dec 10, 2019 12:17 am
- Contact:
Re: Bitwise AND
EDIT Sept,29th: Sorry for mistake!! Here is the correction: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
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: 5529
- Joined: Mon Sep 26, 2011 10:56 am
- Location: Looking forward to summer in Somerset, UK...
- Contact:
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
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
Standby alert 
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Spring approaching...
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp


There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb

Spring approaching...