m |
|||
Line 1: | Line 1: | ||
− | {{mirc title|$xor | + | {{mirc title|$xor identifier}}'''$xor''' returns the binary XOR of the 2 parameters. |
− | '''$xor''' returns the binary XOR of the 2 parameters. | + | |
== Synopsis == | == Synopsis == | ||
Line 12: | Line 12: | ||
== Properties == | == Properties == | ||
− | |||
None | None | ||
== Example == | == Example == | ||
− | |||
XOR is "Exclusive OR" comparison of a pair of bits. It returns 0 if BOTH or NEITHER are 1-bits, and returns 1 if exactly 1 of the pair is a 1-bit. In effect, every 1-bit in the 2nd number toggles the 0/1 state of the corresponding bit of the 1st number<br /> | XOR is "Exclusive OR" comparison of a pair of bits. It returns 0 if BOTH or NEITHER are 1-bits, and returns 1 if exactly 1 of the pair is a 1-bit. In effect, every 1-bit in the 2nd number toggles the 0/1 state of the corresponding bit of the 1st number<br /> | ||
Line 46: | Line 44: | ||
== See also == | == See also == | ||
+ | * {{mIRC|$and}} | ||
* {{mIRC|$or}} | * {{mIRC|$or}} | ||
− | |||
* {{mIRC|$not}} | * {{mIRC|$not}} | ||
+ | * {{mIRC|$bitoff}} | ||
* {{mIRC|$biton}} | * {{mIRC|$biton}} | ||
− | |||
* {{mIRC|$isbit}} | * {{mIRC|$isbit}} | ||
* [[List of identifiers - mIRC]] | * [[List of identifiers - mIRC]] | ||
{{mIRC identifier list}} | {{mIRC identifier list}} | ||
+ | [[Category:mIRC identifiers|xor]] |
Revision as of 07:35, 21 September 2017
$xor returns the binary XOR of the 2 parameters.
Synopsis
$xor(<N1>,<N2>)
Parameters
N1 = 1st Number N2 = 2nd Number Both numbers must be base 10, fractions are ignored. Returns 0 if either number is 2^32 or greater 1.
Properties
None
Example
XOR is "Exclusive OR" comparison of a pair of bits. It returns 0 if BOTH or NEITHER are 1-bits, and returns 1 if exactly 1 of the pair is a 1-bit. In effect, every 1-bit in the 2nd number toggles the 0/1 state of the corresponding bit of the 1st number
//echo -a $xor(21,9) ; returns 28
Here's how the answer was calculated:
- Convert each number to binary, then line them up vertically so there are 2 rows, where each position pair is a single column.
- Create a 3rd row, where each column's 0 or 1 value is the XOR of the bit pair directly above it
- Convert the 3rd row from binary to base 10.
//echo -a $base(21,10,2,8) | echo -a $base(9,10,2,8) | echo -a $str(-,8) | echo -a $base($xor(21,9),10,2,8) ; returns: 00010101 00001001 -------- 00011100
The columns where both numbers are zero remain 0. The columns where only 1 of the 2 values is 1, and the column where both values were 1 is zero.
$xor then returns the answer in base 10. Depending on which bits have changed to 0 or 1, the answer can be less than or greater than the 2 numbers:
//echo -a $base(00011100,2,10) ; returns 28
Compatibility
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.