[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Bitwise XOR in Lua?
- From: Björn De Meyer <bjorn.demeyer@...>
- Date: Sun, 08 Sep 2002 22:34:32 +0200
Reuben Thomas wrote:
> I'll add this routine (and band and bor) to the Lua standard libraries
> project, for those who have a similar problem.
> http://www.mupsych.org/~rrt/ | wit, n. educated insolence (Aristotle)
Well, bor is simply the sum of two positive numbers, IIRC.
Though I'm not sure about negative numbers as they depend
on what type of machine you have.
Anyway, in case you want to inspect the number as a
bitstring, the following function will transform
any positive number to a bit string.
local index, result = 1 , "";
if(num == 0) then return "0"; end
while(num > 0) do
result = math.mod(num,2) .. result;
num = math.floor(num/2);
"No one knows true heroes, for they speak not of their greatness." --
Björn De Meyer