[Coco] replicating bitwise operators in BASIC

Johann Klasek johann+coco at klasek.at
Fri Sep 9 12:26:43 EDT 2016


On Fri, Sep 09, 2016 at 07:14:48AM -0500, Dave Philipsen wrote:
> Actually the XOR could be constructed out of just AND and NOT.
> 

Usually this can be written as

Z = (X OR Y) AND NOT(X AND Y)

and could be optimized to

Z = (X OR Y) - (X AND Y)

X, Y may range from -32768 to 32767 (signed 16 bit integer range)

To get the  unsigned value from a negative signed one you may use
Z = Z - 65536*(Z<0)

(adding 65536 only if the value is negative)
giving results in range from 0 to 65535



Johann K.



More information about the Coco mailing list