bit.bnot
From ComputerCraft Wiki
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 |