[Coco] replicating bitwise operators in BASIC
Johann Klasek
johann+coco at klasek.at
Fri Sep 9 15:46:07 EDT 2016
On Fri, Sep 09, 2016 at 02:23:47PM -0500, Dave Philipsen wrote:
> The less complicated way of doing this on a CoCo (since it has an 'OR'
> operator) would be:
>
> 10 A = 0: B = 0: GOSUB 100
> 20 A = 1: B = 0: GOSUB 100
> 30 A = 0: B = 1: GOSUB 100
> 40 A = 1: B = 1: GOSUB 100
> 90 STOP
> 100 Q = NOT ( A AND B ) AND ( A OR B )
> 110 PRINT "A = ";A;" B = ";B;" Q = ";Q
> 120 RETURN
line 100 is equivalent to
100 Q = ( A OR B ) - ( A AND B )
which is slightly faster, but not very understandable why ... AND NOT(...)
could be replaced by ...-(...) in this special case.
( A OR B ) table
|B
|0 1
---+---
A 0|0 1
1|1 1
(A AND B) table
|B
|0 1
---+---
A 0|0 0
1|0 1
a simple subtraction of the tables removes the 1 for A=1, B=1 in the (A OR
B) table resulting the XOR table.
|B
|0 1
---+---
A 0|0 1
1|1 0
More information about the Coco
mailing list