bit.tobits

From ComputerCraft Wiki
Revision as of 22:38, 11 March 2012 by Hawk777 (Talk | contribs) (Create page)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Grid Redstone.png  Function bit.tobits
Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values
Syntax bit.tobits(number n)
Returns table the bits making up the value n, with entries up to the most-significant 1 bit in n
Part of ComputerCraft
API bit

Examples

Grid paper.png  Example
Convert the number 18 into its binary representation (10010)
Code
for k, v in pairs(bit.tobits(18)) do print(k, ", ", v) end
Output 1, 0
2, 1
3, 0
4, 0
5, 1