[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Kyan Pascal question



David Wilson wrote:
Guillaume Tello wrote:

Hello,

I want to test individual bits into an integer, for example, bit 3 in A
with:
var
 A,B:integer;

begin
B:=A and 8;
...

And I expect, if A=12 to get B=8 and if A=7, to get B=0.

But, this doesn't work. Are those operators (OR, AND, NOT) reserved for
boolean values?


Yep, just like in Applesoft BASIC the AND and OR operators are boolean
rather than bitwise but they do work on all 16 bits. Looking at page
III-100..103 of the Apple Pascal 1.3 manual we find:

INTEGER to BOOLEAN:      ODD(X)
BOOLEAN to INTEGER;      ORD(X)
BOOLEAN to CHAR:           CHR(ORD(X))

Change case of character C

MASK := ODD(32);
C := CHR(ORD((MASK AND NOT ODD(ORD(C))) OR (NOT MASK AND ODD(ORD(C)))));

That's what I love about high level languages--they make complicated
things so simple.  ;-)

-michael

Parallel computing for 8-bit Apple II's!
Home page:  http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."