lua-users home
lua-l archive

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

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.
> --
> | 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. 

function num2bs(num)
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);
return result;

"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer