Difference between revisions of "Bit (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m
m (Fixed grammatical error)
 
(13 intermediate revisions by 6 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.
  
==Methods==
+
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.
{| border="1" cellpadding="2" cellspacing="0"
+
 
!style="background:#EEE" width="200px"|Method name
+
{{API table|Bit|image=Grid disk.png|2=
!style="background:#EEE" width="*"|Description
+
 
|-
+
{{API table/row
|[[bit.tobits]](n)
+
|[[bit.blshift]]({{type|number}} n, {{type|number}} bits)|{{type|number}} value
|Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values
+
|Shifts a number left by a specified number of bits.
|-
+
|odd}}
|[[bit.blshift]](n, bits)
+
 
|Shifts a number left by a specified number of bits
+
{{API table/row
|-
+
|[[bit.brshift]]({{type|number}} n, {{type|number}} bits)|{{type|number}} value
|[[bit.brshift]](n, bits)
+
|Shifts a number right arithmetically by a specified number of bits.
|Shifts a number right by a specified number of bits
+
|}}
|-
+
 
|[[bit.bxor]](m, n)
+
{{API table/row
|Computes the bitwise exclusive OR of two numbers
+
|[[bit.blogic_rshift]]({{type|number}} n, {{type|number}} bits)|{{type|number}} value
|-
+
|Shifts a number right logically by a specified number of bits.
|[[bit.bor]](m, n)
+
|odd}}
|Computes the bitwise inclusive OR of two numbers
+
 
|-
+
{{API table/row
|[[bit.band]](m, n)
+
|[[bit.bxor]]({{type|number}} m, {{type|number}} n)|{{type|number}} value
|Computes the bitwise AND of two numbers
+
|Computes the bitwise exclusive OR of two numbers.
|-
+
|}}
|[[bit.bnot]](n)
+
 
|Computes the bitwise NOT of a number
+
{{API table/row
|-
+
|[[bit.bor]]({{type|number}} m, {{type|number}} n)|{{type|number}} value
|[[bit.tonumb]](bit_tbl)
+
|Computes the bitwise inclusive OR of two numbers.
|Converts an array (numerically-indexed table) of 0 and 1 values representing a number in binary into that number
+
|odd}}
|}
+
 
 +
{{API table/row
 +
|[[bit.band]]({{type|number}} m, {{type|number}} n)|{{type|number}} value
 +
|Computes the bitwise AND of two numbers.
 +
|}}
 +
 
 +
{{API table/row
 +
|[[bit.bnot]]({{type|number}} n)|{{type|number}} value
 +
|Computes the bitwise NOT of a number.
 +
|odd}}
 +
 
 +
}}
 +
 
 +
 
 +
= Deprecated Functions =
 +
{{Deprecated
 +
|plural=yes
 +
|type=These functions
 +
}}
 +
 
 +
{{API table|Bit|image=Grid disk.png|2=
 +
 
 +
{{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}}
 +
 
 +
{{API table/row
 +
|[[bit.tonumb]]({{type|table}} bit_tbl)|{{type|number}} value
 +
|Converts an array (numerically-indexed table) of 0 and 1 values representing a number in binary into that number.
 +
|odd}}
 +
 
 +
}}
  
 
[[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.