问题
I am converting an old program written on Mac Think Pascal to Pascal on Windows. Think Pascal has functions for bit manipulations, such as
btst(n, i : longint) : boolean
bitxor(i, j : longint) : longint
bclr(n, i : longint) : longint
bset(n, i : longint) : longint
...and others. If you know what these functions do, please help.
I have found some related information, for example "Porting to GNU Pascal from traditional Macintosh Pascal compilers". This document has implementations of the bit functions using bitwise operators like and
, or
, shr
and shl
. However, I am not sure that the description in the document is correct.
I know approximate meaning of the functions:
btst(n,i)
is True, if i-th bit of n is 1, and False otherwisebitxor(i,j)
is bitwise 'xor'bclr(n, i)
sets i-th bit of n to 0bset(n, i)
sets i-th bit of n to 1
However, I don't know what is the correct order of variables in the functions (e.g. btst(n,i)
or btst(i,n)
). Also, how bits are numbered? From left to right, starting from 0 or 1? Thank you for any help on these four functions.
回答1:
(sorry, needed some more room)
The build in Free Pascal of Dev Pascal 1.9.2 is essentially a beta, and very, very old, and lacks such features since it is 2002 era. But dev-pascal can be used with newer FPC's I'm told. Lazarus is pretty close to recompiling the thing itself :_)
Put {$mode macpas} after the program and/or "interface" line (in an unit). Commandline is also possible, -Mmacpas (goes for all compiled by that invocation of the compiler unless overruled by $mode in source)
The functions you name are supported in mode MacPasc, but bitxor is called bxor(). Afaik MacPascal mostly models CodeWarrior Pascal, but since that is mostly a superset Think afaik usually works fine. Some Thinkisms were added.
Since macpascal knowledge is fairly rare, you might want to subscribe either to the main fpc list main fpc list or the Mac Pascal List.
The General Lazarus Forum is also abused for FPC purposes, though I expect less people knowledgeable about old Apple dialects there.
来源:https://stackoverflow.com/questions/16218767/bit-functions-in-think-pascal