local function b(b,W,s,D)local j local m D=D%s if D==0 then return b end j=bit32.extract(b,W,D)j=bit32.lshift(j,s-D)m=bit32.extract(b,W+D,s-D)return bit32.replace(b,bit32.bor(j,m),W,s)end function BitOps.rotateConnectivity(W,s)return b(W,0,24,(6*(s%360))/90)end function BitOps.rotateOccupancy(W,s)local D=b(W,2,4,(s%360)/90)return b(D,6,8,(2*(s%360))/90)end
-- 0 = Least Significant Bit, 31 = Most Significant Bit
local function rRotateSubsection(int, start, width, disp)
	local wrappedBits
	local shiftedBits

	disp = disp % width
	if disp == 0 then
		return int
	end

	wrappedBits = bit32.extract(int, start, disp)
	wrappedBits = bit32.lshift(wrappedBits, width - disp)
	shiftedBits = bit32.extract(int, start + disp, width - disp)

	return bit32.replace(int, bit32.bor(wrappedBits, shiftedBits), start, width)
end

function BitOps.rotateConnectivity(connectivity, degrees)
	return rRotateSubsection(connectivity, 0, 24, 6 * (degrees % 360) / 90)
end

function BitOps.rotateOccupancy(occupancy, degrees)
	local occupancyWithVerticalFacesRotated = rRotateSubsection(occupancy, 2, 4, (degrees % 360) / 90)
	return rRotateSubsection(occupancyWithVerticalFacesRotated, 6, 8, 2 * (degrees % 360) / 90)
end
