[Coco] replicating bitwise operators in BASIC
William Astle
lost at l-w.ca
Sun Sep 11 00:04:43 EDT 2016
For specific cases, you might be able to fake it with addition and
subtraction only (like setting a bit you know isn't set or clearing a
bit you know is set). For the general case, your best bet would be to
take apart the values into bit values, apply the operation, then put the
values back together.
For the actual AND/OR/NOT operations for each bit, you can use boolean
operators in an IF/ELSE statement or some clever expression. If you
don't have boolean operators for conditionals, then you would need
either a multi-level IF/ELSE statement or a truth table.
On 2016-09-10 09:47 PM, Dave Philipsen 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 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.
>
> Dave
>
>
> On 9/10/2016 10:26 PM, Brett Gordon wrote:
>> Bogus test?
>>
>> 1.5 = 0b01.10
>> 3.25 = 0b11.01
>>
>> The fractional part would disappear even if BASIC did keep the fractions.
>> :)
>>
>> As the OP... I point out nobody actually answered my intended question:
>> what if we had no AND, OR, or NOT... is it possible to replicate these
>> from
>> other means?
>>
>> Lost: I consider USR()'ing cheating. ;)
>>
>> cheers, brett
>>
>
>
More information about the Coco
mailing list