Difference between revisions of "Bit.tobits"
From ComputerCraft Wiki
(Add link to inverse) |
|||
| Line 11: | Line 11: | ||
|desc=Convert the number 18 into its binary representation (10010) | |desc=Convert the number 18 into its binary representation (10010) | ||
|code=for k, v in pairs(bit.tobits(18)) do print(k, ", ", v) end | |code=for k, v in pairs(bit.tobits(18)) do print(k, ", ", v) end | ||
| − | |output=1, 0<br>2, 1<br>3, 0<br>4, | + | |output=1, 0<br>2, 1<br>3, 0<br>4, 1<br>5, 0 |
}} | }} | ||
}} | }} | ||
Revision as of 13:56, 3 October 2012
| Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values (the inverse of bit.tonumb) | |
| Syntax | bit.tobits(int 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
| 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, 1 5, 0 |