Difference between revisions of "Bit (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Now perhaps jesusthekiller won't submit false bugreports.)
m (Fixed grammatical error)
 
(4 intermediate revisions by 3 users not shown)
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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.blshift]]({{Type|int}} n, {{Type|int}} 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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.brshift]]({{Type|int}} n, {{Type|int}} 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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.blogic_rshift]]({{Type|int}} n, {{Type|int}} 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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.bxor]]({{Type|int}} m, {{Type|int}} 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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.bor]]({{Type|int}} m, {{Type|int}} 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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.band]]({{Type|int}} m, {{Type|int}} 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|int}} value</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.bnot]]({{Type|int}} n)</td>
+
|[[bit.bnot]]({{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 number.
</table>
+
|odd}}
 +
 
 +
}}
  
  
Line 42: Line 49:
 
}}
 
}}
  
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
+
{{API table|Bit|image=Grid disk.png|2=
<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/row
 +
|[[bit.tobits]]({{type|number}} n)|{{type|table}} bit_tbl
 +
|Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values.
 +
|odd}}
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|table}} bit_tbl</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.tobits]]({{Type|int}} n)</td>
+
|[[bit.tonumb]]({{type|table}} bit_tbl)|{{type|number}} value
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values.</td></tr>
+
|Converts an array (numerically-indexed table) of 0 and 1 values representing a number in binary into that number.
 +
|odd}}
  
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">{{Type|int}} value</td>
+
}}
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[bit.tonumb]]({{Type|table}} bit_tbl)</td>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Converts an array (numerically-indexed table) of 0 and 1 values representing a number in binary into that number.</td></tr>
+
</table>
+
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Latest revision as of 01:23, 18 March 2014

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.bnot(number n) number value Computes the bitwise NOT of a number.


Deprecated Functions

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