[Coco] replicating bitwise operators in BASIC

Dave Philipsen dave at davebiz.com
Sun Sep 11 00:34:37 EDT 2016


On 9/10/2016 11:05 PM, Brett Gordon wrote:
> On Sep 10, 2016 11:48 PM, "Dave Philipsen" <dave at davebiz.com> wrote:
>> One way to do it without boolean operators is to simply use a truth table
> for the logic as a lookup table.  For integers large than 0-1 (single bit)
> you'd have to rotate through all of the bits (up to 15).  Since ECB doesn't
> have a rotate function
>
> Dividing and multiplying by powers of 2 could be used as shifts?

Yeah, but I could see that getting a little messy and possibly more time 
consuming.  Would ECB automatically convert to floating point to do the 
division/multiplication?  Not sure right offhand.

Typically, the way I would do it is something like this

IF X > 16383 THEN X = X-16384: <CODE HERE TO PROCESS AS '1'>  ELSE <CODE 
HERE TO PROCESS AS '0'>
IF X > 8191 THEN....
IF X > 4095 THEN...
....

You'd have to do the same with the second operand.

Then as William suggested you'd have to add the resulting bits back 
together.


Dave



>
> and you've asked to do it without AND then you may have to extract the
> individual bits through a subtraction routine.  I think it could still be
> relatively quick using tables for the logic and tables for the subtraction
> though definitely not as quick as having the logic operators.
>
> Ah..look up tables.. there's an idea.
>



More information about the Coco mailing list