Difference between revisions of "Bit.tobits"
From ComputerCraft Wiki
(Fix type) |
(Add link to inverse) |
||
| Line 6: | Line 6: | ||
|returns=[[table]] the bits making up the value <var>n</var>, with entries up to the most-significant 1 bit in <var>n</var> | |returns=[[table]] the bits making up the value <var>n</var>, with entries up to the most-significant 1 bit in <var>n</var> | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
| − | |desc=Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values | + | |desc=Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values (the inverse of [[bit.tonumb]]) |
|examples= | |examples= | ||
{{Example | {{Example | ||
Revision as of 23:08, 11 March 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, 0 5, 1 |