--Lua--十进制转二进制functiondec_to_binary (data)
local dst= ""local remainder, quotient--异常处理if not data then return dst end --源数据为空if not tonumber(data) then return dst end --源数据无法转换为数字--如果源数据是字符串转换为数字if "string" ==type(data) then
data=tonumber(data)
endwhile true doquotient= math.floor(data / 2)
remainder= data % 2dst=dst..remainder
data=quotientif 0 ==quotient thenbreakend
end--翻转
dst=string.reverse(dst)--补齐8位if 8 >#dst thenfor i = 1, 8 - #dst, 1 dodst= '0'..dst
end
endreturndst
end--Lua--二进制转十进制functionbinary_to_dec (data)
local dst= 0local tmp= 0
--异常处理if not data then return dst end --源数据为空if not tonumber(data) then return dst end --源数据无法转换为数字--如果源数据是字符串去除前面多余的0if "string" ==type(data) then
data=tostring(tonumber(data))
en