Difference between revisions of "Bit.bnot"

From ComputerCraft Wiki
Jump to: navigation, search
m (Moved to CAT:APIFunctions)
m (Int linking fix.)
Line 4: Line 4:
 
|args=[[int (type)|int]] n
 
|args=[[int (type)|int]] n
 
|api=bit
 
|api=bit
|returns=[[int]] the value of NOT <var>n</var>
+
|returns=[[int (type)|int]] 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

Revision as of 18:35, 30 November 2012


Grid Redstone.png  Function bit.bnot
Computes the bitwise NOT of a number, taken in the domain and range of 32-bit unsigned integers
Syntax bit.bnot(int n)
Returns int the value of NOT n
Part of ComputerCraft
API bit

Examples

Grid paper.png  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