From WikiChip
Difference between revisions of "mirc/identifiers/$and"
< mirc‎ | identifiers

(Created page with "{{mirc title|$and Identifier}}'''$and''' returns the AND operation of the two numbers, the numbers are decimal not binary. == Synopsis == <pre>$addtok(<A>,<B>)</pre> == Para...")
 
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{mirc title|$and Identifier}}'''$and''' returns the AND operation of the two numbers, the numbers are decimal not binary.
+
{{mirc title|$and identifier}}'''$and''' returns the AND operation of two numbers.
  
== Synopsis ==
+
'''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.
<pre>$addtok(<A>,<B>)</pre>
 
  
== Paramters ==
+
Valid range for N1 and N2 are -4294967295 through +4294967295. See '''{{mIRC|$xor}}''' for description of handling out-of-range and negative numbers.
  
* '''<A>''' - The first number
+
== Synopsis ==
* '''<B>''' - The second number
+
<pre>$and(<N1>,<N2>)</pre>
  
 +
== Parameters ==
 +
* '''<N1>''', '''<N2>''' - The numbers, in decimal
 
== Properties ==
 
== Properties ==
 
None
 
None
  
 
== Example ==
 
== Example ==
<source lang="mIRC">//echo -a $and(7,32)</source>
+
<source lang="mIRC">//echo -a $and(14,27)
Would display "0", only bit which are both 1 gives 1, otherwise it gives 0
+
; returns 10
7 is in  binary: 000111
+
; 14 is 00001110 when converted to binary
                &         
+
; 27 is 00011011 when converted to binary
32 is in binary: 100000
+
; AND  00001010 which is 10 when converted back to decimal
               
+
</source>
                000000
+
 
 +
The AND operation returns a 1 when both matching binary bits are 1, otherwise returns 0
  
== Compatibility ==
+
<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)
{{mIRC compatibility|5.61}}
+
returns:
 +
00001110
 +
00011011
 +
--------
 +
00001010 -> 10
  
== See Also ==
+
$and returns the answer as a decimal number, so the answer 10 is the decimal representation of binary 1010.
{{mIRC|$not}}
 
{{mIRC|$or}}
 
{{mIRC|$xor}}
 
{{mIRC|$biton}}
 
{{mIRC|$bitoff}}
 
{{mIRC|$isbit}}
 
  
 +
//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>
  
[[Category:MIRC identifiers]]
+
== Compatibility ==
 +
{{mIRC compatibility|5.61}}
 +
== See also ==
 +
* {{mIRC|$not}}
 +
* {{mIRC|$or}}
 +
* {{mIRC|$xor}}
 +
* {{mIRC|$biton}}
 +
* {{mIRC|$bitoff}}
 +
* {{mIRC|$isbit}}

Latest revision as of 18:45, 20 May 2018

$and returns the AND operation of two numbers.

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 $xor for description of handling out-of-range and negative numbers.

Synopsis[edit]

$and(<N1>,<N2>)

Parameters[edit]

  • <N1>, <N2> - The numbers, in decimal

Properties[edit]

None

Example[edit]

//echo -a $and(14,27)
; returns 10
; 14 is 00001110 when converted to binary
; 27 is 00011011 when converted to binary
; AND   00001010 which is 10 when converted back to decimal

The AND operation returns a 1 when both matching binary bits are 1, otherwise returns 0

//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)
returns:
00001110
00011011
--------
00001010 -> 10
 
$and returns the answer as a decimal number, so the answer 10 is the decimal representation of binary 1010.
 
//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.

Compatibility[edit]

Added: mIRC v5.61
Added on: 23 Sep 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.

See also[edit]