From WikiChip
Difference between revisions of "mirc/identifiers/$xor"
Maroonbells (talk | contribs) (Create content for empty stub) |
|||
Line 1: | Line 1: | ||
− | ''' | + | {{mirc title|$xor Identifier}} |
+ | '''$xor''' returns the binary XOR of the 2 parameters. | ||
== Synopsis == | == Synopsis == |
Revision as of 19:37, 17 June 2017
Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Advanced Scripting
Additional Resources
Security
Other
$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<br /> <pre>//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.
See also
mIRC identifier list