Line 3: | Line 3: | ||
== Synopsis == | == Synopsis == | ||
− | <pre>$xor(<N1>,<N2>) | + | <pre>$xor(<N1>,<N2>)</pre> |
== Parameters == | == Parameters == | ||
Line 19: | Line 19: | ||
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 /> | ||
− | < | + | <source lang=mirc>//echo -a $xor(21,9) |
− | ; returns 28</ | + | ; returns 28</source> |
Here's how the answer was calculated: | Here's how the answer was calculated: | ||
Line 27: | Line 27: | ||
# Convert the 3rd row from binary to base 10. | # Convert the 3rd row from binary to base 10. | ||
− | < | + | <source lang=mirc>//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: | ; returns: | ||
00010101 | 00010101 | ||
Line 33: | Line 33: | ||
-------- | -------- | ||
00011100 | 00011100 | ||
− | </ | + | </source> |
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. | 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. | ||
Line 39: | Line 39: | ||
$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: | $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: | ||
− | < | + | <source lang=mirc>//echo -a $base(00011100,2,10) |
− | ; returns 28</ | + | ; returns 28</source> |
== Compatibility == | == Compatibility == |
Revision as of 19:40, 17 June 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.