首页 > 其他 > 详细

lua 十进制转二进制

时间:2019-10-25 18:48:21      阅读:1420      评论:0      收藏:0      [点我收藏+]
-- 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

lua 十进制转二进制

原文:https://www.cnblogs.com/v5captain/p/11739414.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!