From WikiChip
Editing mirc/identifiers/$and

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
{{mirc title|$and identifier}}'''$and''' returns the AND operation of two numbers.
+
{{mirc title|$and identifier}}'''$and''' returns the AND operation of the two numbers, the numbers are decimal not binary.
  
'''Note:''' The numbers need to be provided in decimal, and are then converted to binary, the AND operation applied, and  the answer converted back to decimal.
 
 
Valid range for N1 and N2 are -4294967295 through +4294967295. See '''{{mIRC|$xor}}''' for description of handling out-of-range and negative numbers.
 
  
 
== Synopsis ==
 
== Synopsis ==
Line 9: Line 6:
  
 
== Parameters ==
 
== Parameters ==
* '''<N1>''', '''<N2>''' - The numbers, in decimal
+
* '''<N1>''', '''<N2>''' - The numbers
 +
 
 
== Properties ==
 
== Properties ==
 
None
 
None
  
 
== Example ==
 
== Example ==
<source lang="mIRC">//echo -a $and(14,27)
+
<source lang="mIRC">//echo -a $or(14,27)
; returns 10
+
; returns 31
; 14 is 00001110 when converted to binary
 
; 27 is 00011011 when converted to binary
 
; AND  00001010 which is 10 when converted back to decimal
 
 
</source>
 
</source>
  
The AND operation returns a 1 when both matching binary bits are 1, otherwise returns 0
+
Bits which are both 0 return 0, otherwise the bit is 1
  
<source lang="mIRC">//var %n1 14 | var %n2 27 | echo -a $base(%n1,10,2,8) | echo -a $base(%n2,10,2,8) | echo -a $str(-,8) | echo -a $base($and(%n1,%n2),10,2,8) -> $and(%n1,%n2)
+
<pre>//var %n1 14 | var %n2 27 | echo -a $base(%n1,10,2,8) | echo -a $base(%n2,10,2,8) | echo -a $str(-,8) | echo -a $base($and(%n1,%n2),10,2,8)
returns:
+
; returns:
 
00001110
 
00001110
 
00011011
 
00011011
 
--------
 
--------
00001010 -> 10
+
00001010
  
 
$and returns the answer as a decimal number, so the answer 10 is the decimal representation of binary 1010.
 
$and returns the answer as a decimal number, so the answer 10 is the decimal representation of binary 1010.
 
+
</pre>
//var %a 127 | var %bits 3 | var %b $and(%a,$calc(-2^%bits)) | echo -a $base(%a,10,16,8) $base(%b,10,16,8)
 
Zeroes the lowest 3 bits, which ensures that %b is a multiple of 8.
 
</source>
 
  
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|5.61}}
 
{{mIRC compatibility|5.61}}
 +
 
== See also ==
 
== See also ==
 
* {{mIRC|$not}}
 
* {{mIRC|$not}}
Line 45: Line 38:
 
* {{mIRC|$bitoff}}
 
* {{mIRC|$bitoff}}
 
* {{mIRC|$isbit}}
 
* {{mIRC|$isbit}}
 +
* [[List of identifiers - mIRC]]
 +
{{mIRC identifier list}}
 +
[[Category:mIRC identifiers|and]]

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)