Difference between revisions of "Bit.bor"

From ComputerCraft Wiki
Jump to: navigation, search
(0V0=0; 1V0=1; 0V1=1; 1V1=1;)
 
m (Changed nonexistent type int to type number.)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{lowercase}}
 +
{{Function
 +
|name=bit.bor
 +
|args={{Type|number}} m, {{Type|number}} n
 +
|api=bit
 +
|returns={{Type|number}} the value of <var>m</var> OR <var>n</var>
 +
|addon=ComputerCraft
 +
|desc=Computes the bitwise inclusive OR of two numbers
 +
|examples=
 +
{{Example
 +
|desc=OR the number 18 (10010) with the number 3 (00011), yielding 19 (10011)
 +
|code=print(bit.bor(18, 3))
 +
|output=19
 +
}}
 +
}}
  
 
== Explanation ==
 
== Explanation ==
<i>OR</i> outputs the sum of the two values(ex. (1,0)=1; (0,1)=1; (2,0)=2; (2,1)=3), unless they are equal in which it outputs the number. (ex. (0,0)=0; (1,1)=1; (2,2)=2; (3,3)=3)
+
All bit operations operate in binary numeral system [http://en.wikipedia.org/wiki/Binary_numeral_system]. An inclusive OR operation between two bits yields a 1 if either of the bits is 1 and a 0 if they are both 0. This function produces an output by computing the OR of each bit of its two inputs independently. So, for the example above:
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Bit index:
 +
| 4
 +
| 3
 +
| 2
 +
| 1
 +
| 0
 +
|-
 +
! Input 1 (18):
 +
| 1
 +
| 0
 +
| 0
 +
| 1
 +
| 0
 +
|-
 +
! Input 2 (3):
 +
| 0
 +
| 0
 +
| 0
 +
| 1
 +
| 1
 +
|-
 +
! Calculation:
 +
| 18 has a 1
 +
| Both 0
 +
| Both 0
 +
| Both 1
 +
| 3 has a 1
 +
|-
 +
! Output (19):
 +
| 1
 +
| 0
 +
| 0
 +
| 1
 +
| 1
 +
|}
 +
 
 +
[[Category:API_Functions]]

Latest revision as of 01:34, 12 July 2013


Grid Redstone.png  Function bit.bor
Computes the bitwise inclusive OR of two numbers
Syntax bit.bor(number m, number n)
Returns number the value of m OR n
Part of ComputerCraft
API bit

Examples

Grid paper.png  Example
OR the number 18 (10010) with the number 3 (00011), yielding 19 (10011)
Code
print(bit.bor(18, 3))
Output 19


Explanation

All bit operations operate in binary numeral system [1]. An inclusive OR operation between two bits yields a 1 if either of the bits is 1 and a 0 if they are both 0. This function produces an output by computing the OR of each bit of its two inputs independently. So, for the example above:

Bit index: 4 3 2 1 0
Input 1 (18): 1 0 0 1 0
Input 2 (3): 0 0 0 1 1
Calculation: 18 has a 1 Both 0 Both 0 Both 1 3 has a 1
Output (19): 1 0 0 1 1