Difference between revisions of "Bit.bnot"

From ComputerCraft Wiki
Jump to: navigation, search
(Undo revision 1868 by 91.121.27.33 (talk))
m (Changed nonexistent type int to type number.)
 
(3 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=bit.bnot
 
|name=bit.bnot
|args=[[int (type)|int]] n
+
|args={{Type|number}} n
 
|api=bit
 
|api=bit
|returns=[[int]] the value of NOT <var>n</var>
+
|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
Line 122: Line 122:
 
| 1
 
| 1
 
|}
 
|}
 +
 +
[[Category:API_Functions]]

Latest revision as of 01:51, 12 July 2013


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(number n)
Returns number 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