lua 十进制转二进制


-- Converts a byte to a string of 0s and 1s.
function byte2bin(n)
local t = {}
  for i=7,0,-1 do
    t[#t+1] = math.floor(n / 2^i)
    n = n % 2^i
  end
  return table.concat(t)
end

a = byte2bin(127)
print(a)

输出:

01111111

 

原文 :

http://love2d.org/forums/viewtopic.php?f=4&t=84988&start=10


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM