local function B(B,H,t,E)local g local W E=E%t if E==0 then return B end g=bit32.extract(B,H,E)g=bit32.lshift(g,t-E)W=bit32.extract(B,H+E,t-E)return bit32.replace(B,bit32.bor(g,W),H,t)end function BitOps.rotateConnectivity(H,t)return B(H,0,24,(6*(t%360))/90)end function BitOps.rotateOccupancy(H,t)local E=B(H,2,4,(t%360)/90)return B(E,6,8,(2*(t%360))/90)end

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
