Functional 32Bit adder

Here is a Bit32 adder script I made. (does not yet support negative numbers)

local b32 = {}
b32.__Index = b32


function b32.Adder(n1:number,n2:number)
	local R = 0
	local Sequence = ''
	for c=0,31 do
		local bit1 = bit32.extract(n1,c)
		local bit2 = bit32.extract(n2,c)
		local tot = bit1 + bit2 + R
		if tot == 3 then
			Sequence..=1
			R=1
		elseif tot == 2 then
			Sequence..=0
			R=1
		elseif tot == 1 then
			Sequence..=1
			R=0
		elseif tot == 0 then
			Sequence..= 0
			R=0
		end

	end
	local Output = tonumber(string.reverse(Sequence),2)
	return Output
end



return b32
3 Likes

I made a far more effiecent and faster Bit32 adder in my SimpleBit module.