Difference between revisions of "Bit.bnot"
From ComputerCraft Wiki
m (Use type template) |
m (Changed nonexistent type int to type number.) |
||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=bit.bnot | |name=bit.bnot | ||
− | |args={{Type| | + | |args={{Type|number}} n |
|api=bit | |api=bit | ||
− | |returns={{Type| | + | |returns={{Type|number}} the value of NOT <var>n</var> |
|addon=ComputerCraft | |addon=ComputerCraft | ||
|desc=Computes the bitwise NOT of a number, taken in the domain and range of 32-bit unsigned integers | |desc=Computes the bitwise NOT of a number, taken in the domain and range of 32-bit unsigned integers |
Latest revision as of 01:51, 12 July 2013
Function bit.bnot | |
Computes the bitwise NOT of a number, taken in the domain and range of 32-bit unsigned integers | |
Syntax | bit.bnot(number n) |
Returns | number the value of NOT n |
Part of | ComputerCraft |
API | bit |
Examples
Example | |
NOT the number 18 (10010), yielding 4294967277 (11111111111111111111111111101101, 32 bits in length) | |
Code |
print(bit.bnot(18)) |
Output | 4294967277 |
Explanation
All bit operations operate in binary numeral system [1]. A NOT operation yields a 1 if its input is 0 and a 0 if its input is 1. This function produces an output by computing the NOT of each bit of its input independently. So, for the example above:
Bit index: | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Input (18): | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
Output (4294967277): | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |