Difference between revisions of "Bit (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Int -> {{type|number}})
Line 1: Line 1:
 
The Bit API is for manipulating numbers using bitwise binary operations.
 
The Bit API is for manipulating numbers using bitwise binary operations.
  
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
+
All of these functions treat the numbers as 32-bit integers, and will raise an error if an input number is greater than 4,294,967,295.
<tr><td colspan="3" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">[[File:Grid_disk.png|24px]]&nbsp;&nbsp;Bit (API)</td></tr>
+
  
<tr><td style="width: 100px; background: #E0E0E0; padding: .4em; font-weight:bold;">Return</td><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
+
{{API table|Bit|image=Grid disk.png|2=
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.blshift]]({{Type|number}} n, {{Type|number}} bits)</td>
+
|[[bit.blshift]]({{type|number}} n, {{type|number}} bits)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Shifts a number left by a specified number of bits.</td></tr>
+
|Shifts a number left by a specified number of bits.
 +
|odd}}
  
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.brshift]]({{Type|number}} n, {{Type|number}} bits)</td>
+
|[[bit.brshift]]({{type|number}} n, {{type|number}} bits)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Shifts a number right arithmetically by a specified number of bits.</td></tr>
+
|Shifts a number right arithmetically by a specified number of bits.
 +
|}}
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.blogic_rshift]]({{Type|number}} n, {{Type|number}} bits)</td>
+
|[[bit.blogic_rshift]]({{type|number}} n, {{type|number}} bits)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Shifts a number right logically by a specified number of bits.</td></tr>
+
|Shifts a number right logically by a specified number of bits.
 +
|odd}}
  
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.bxor]]({{Type|number}} m, {{Type|number}} n)</td>
+
|[[bit.bxor]]({{type|number}} m, {{type|number}} n)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Computes the bitwise exclusive OR of two numbers.</td></tr>
+
|Computes the bitwise exclusive OR of two numbers.
 +
|}}
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.bor]]({{Type|number}} m, {{Type|number}} n)</td>
+
|[[bit.bor]]({{type|number}} m, {{type|number}} n)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Computes the bitwise inclusive OR of two numbers.</td></tr>
+
|Computes the bitwise inclusive OR of two numbers.
 +
|odd}}
  
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.band]]({{Type|number}} m, {{Type|number}} n)</td>
+
|[[bit.band]]({{type|number}} m, {{type|number}} n)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Computes the bitwise AND of two numbers.</td></tr>
+
|Computes the bitwise AND of two numbers.
 +
|}}
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|number}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.bnot]]({{Type|number}} n)</td>
+
|[[bit.band]]({{type|number}} n)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Computes the bitwise NOT of a number.</td></tr>
+
|Computes the bitwise NOT of a numbers.
</table>
+
|odd}}
 +
 
 +
}}
  
  

Revision as of 03:07, 25 August 2013

The Bit API is for manipulating numbers using bitwise binary operations.

All of these functions treat the numbers as 32-bit integers, and will raise an error if an input number is greater than 4,294,967,295.

Grid disk.png  Bit (API)
Function Return values Description
bit.blshift(number n, number bits) number value Shifts a number left by a specified number of bits.
bit.brshift(number n, number bits) number value Shifts a number right arithmetically by a specified number of bits.
bit.blogic_rshift(number n, number bits) number value Shifts a number right logically by a specified number of bits.
bit.bxor(number m, number n) number value Computes the bitwise exclusive OR of two numbers.
bit.bor(number m, number n) number value Computes the bitwise inclusive OR of two numbers.
bit.band(number m, number n) number value Computes the bitwise AND of two numbers.
bit.band(number n) number value Computes the bitwise NOT of a numbers.


Deprecated Functions

These functions have been deprecated.
These functions have been removed from ComputerCraft .
Grid disk.png  Bit (API)
ReturnMethod nameDescription
table bit_tbl bit.tobits(number n) Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values.
number value bit.tonumb(table bit_tbl) Converts an array (numerically-indexed table) of 0 and 1 values representing a number in binary into that number.