PICO-8 Wiki
m (→‎See also: add lshr)
(superseded by &)
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
{{Superseded}}
 
{{ApiReference
 
{{ApiReference
 
|name=band
 
|name=band
Line 5: Line 6:
 
|second||The second number.
 
|second||The second number.
 
}}
 
}}
  +
  +
== Superseded by & operator ==
  +
  +
The <code>&</code> operator added in 0.2.0 performs the same function as <code>band()</code> and is now the recommended way to do bitwise and, as it uses fewer tokens, costs fewer cycles at runtime, and runs on the real host CPU much more efficiently. Simply replace <code>band(a,b)</code> with <code>a&b</code>.
   
 
== Examples ==
 
== Examples ==
Line 13: Line 18:
 
-- 0x5 = 0101 binary
 
-- 0x5 = 0101 binary
 
print(band(0x7, 0xd)) -- 5
 
print(band(0x7, 0xd)) -- 5
  +
  +
print(0x7 & 0xd) -- preferred method
 
</syntaxhighlight>
 
</syntaxhighlight>
   
Line 21: Line 28:
 
* [[Bxor|<code>bxor()</code>]]
 
* [[Bxor|<code>bxor()</code>]]
 
* [[Bnot|<code>bnot()</code>]]
 
* [[Bnot|<code>bnot()</code>]]
* [[Shr|<code>lshr()</code>]]
+
* [[Lshr|<code>lshr()</code>]]
 
* [[Shl|<code>shl()</code>]]
 
* [[Shl|<code>shl()</code>]]
 
* [[Shr|<code>shr()</code>]]
 
* [[Shr|<code>shr()</code>]]
  +
* [[Rotl|<code>rotl()</code>]]
  +
* [[Rotr|<code>rotr()</code>]]
 
[[Category:Reference]]
 
[[Category:Reference]]
 
[[Category:API]]
 
[[Category:API]]

Revision as of 04:47, 6 May 2020

Superseded / Deprecated
The feature described in this article has been superseded by a newer feature. This feature still works in PICO-8, but the new feature should be used instead. See the article's "Superseded by..." section for specific details.
band( first, second )
Calculates the bitwise and of two numbers.
first
The first number.

second
The second number.

Superseded by & operator

The & operator added in 0.2.0 performs the same function as band() and is now the recommended way to do bitwise and, as it uses fewer tokens, costs fewer cycles at runtime, and runs on the real host CPU much more efficiently. Simply replace band(a,b) with a&b.

Examples

--     0x7 = 0111 binary
-- and 0xd = 1101 binary
-- -------
--     0x5 = 0101 binary
print(band(0x7, 0xd))  -- 5

print(0x7 & 0xd)       -- preferred method

See also