[Coco] replicating bitwise operators in BASIC

Dave Philipsen dave at davebiz.com
Fri Sep 9 16:04:59 EDT 2016


Probably has to do with the fact that the interpreter is parsing and 
performing four logical operations in the first case and only two 
logical operations and a subtraction in the second case.  But in pure 
logic you probably wouldn't use a subtraction since that would be more 
complicated than the logic operations.  The subtraction itself would be 
boiled down to some NAND gates...



On 9/9/2016 2:46 PM, Johann Klasek wrote:
> 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