BitXorString (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
No edit summary
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Template:String:BitXorString subtitle}}
{{Template:String:BitXorString subtitle}}
 
<var>BitXorString</var> does a logical XOR (exclusive OR) of the bits in two strings.  
<var>BitXorString</var> does a logical XOR of the bits in two strings.  


==Syntax==
==Syntax==
Line 7: Line 6:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%result</th><td>A string to receive the result of XORing together the bits in <var class="term">string</var> and <var class="term">xorBits</var>.</td></tr>
<tr><th nowrap>%result</th><td>A string to receive the result of XORing together the bits in <var class="term">string</var> and <var class="term">xorBits</var>.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>One of the strings to be XORed.</td></tr>
<td>One of the strings to be XORed.</td></tr>
Line 13: Line 12:
<td>The other string to be XORed.</td></tr>
<td>The other string to be XORed.</td></tr>
<tr><th><var>Pad</var></th>
<tr><th><var>Pad</var></th>
<td>A single character that indicates the character with which the shorter of the two input strings is to be extended. As many copies of <var class="term">pad</var> are used as is required to make the shorter string as long as the longer. If both strings are of equal length, no padding is required. The default value of <var class="term">pad</var> is <code>'00':x</code>.</td></tr>
<td>A single character that indicates the character with which the shorter of the two input strings is to be extended. As many copies of <var class="term">c</var> are used as is required to make the shorter string as long as the longer. If both strings are of equal length, no padding is required. The default value of <var class="term">c</var> is <code>'00':x</code>.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>Using a null <var class="term">string</var> or <var class="term">xorBits</var> is an easy way of XORing each byte in a string with a specific byte value (the <var class="term">pad</var> value).
<li>Using a null <var class="term">string</var> or <var class="term">xorBits</var> is an easy way of XORing each byte in a string with a specific byte value (the <var>Pad</var> value).
 
<li><var>BitXorString</var> is most useful for working with binary data, for example binary data being sent or received with <var class="product">[[Janus Sockets]]</var>.
<li><var>BitXorString</var> is most useful for working with binary data, for example binary data being sent or received with <var class="product">[[Janus Sockets]]</var>.
<li><var>BitXorString</var> was introduced in <var class="product">[[Sirius Mods|Sirius Mods]]</var> version 7.9.
</ul>
</ul>


==Examples==
The following example compares the result of <var>BitXorString</var> (logical exclusive OR) versus
<var>[[BitOrString (String function)|BitOrString]]</var> (logical inclusive OR):
<p class="code">b                                                               
printText {~='Ale':stringToHex}                                 
printText {~='Lager':stringToHex}
print '======================' 
printText {~='Ale':bitOrString('Lager', pad='40':x)}           
printText {~='Ale':bitOrString('Lager', pad='40':x):stringToHex}
print '======================' 
printText {~='Ale':bitXorString('Lager', pad='40':x)}           
printText {~='Ale':bitXorString('Lager', pad='40':x):stringToHex}
end </p>
The result is:
<p class="code">'Ale':stringToHex=C19385                                     
'Lager':stringToHex=D381878599                               
&#61;=====================
'Ale':bitOrString('Lager', pad='40':x)=LlgER                 
'Ale':bitOrString('Lager', pad='40':x):stringToHex=D39387C5D9
&#61;=====================
'Ale':bitXorString('Lager', pad='40':x)=???ER               
'Ale':bitXorString('Lager', pad='40':x):stringToHex=121202C5D9
</p>


==See also==
==See also==
<table>
<tr>
<td>
<ul>
<li><var>[[BitAndString (String function)|BitAndString]]</var>
<li><var>[[BitOffString (String function)|BitOffString]]</var>
<li><var>[[BitOnString (String function)|BitOnString]]</var>
<li><var>[[BitOrString (String function)|BitOrString]]</var>
</ul>
</td>
<td>
<ul>
<li><var>[[BitClearString, BitFlipString, and BitSetString (String functions)|BitClearString, BitFlipString, and BitSetString]]</var>
<li><var>[[BitValueString (String function)|BitValueString]]</var>
<li><var>[[BitCountString (String function)|BitCountString]]</var>
</ul>
</td>
</table>
[[Category:Bit manipulation methods]]
{{Template:String:BitXorString footer}}
{{Template:String:BitXorString footer}}

Latest revision as of 20:46, 3 September 2015

Do bitwise exclusive Or of strings (String class)

[Introduced in Sirius Mods 7.9]

BitXorString does a logical XOR (exclusive OR) of the bits in two strings.

Syntax

%result = string:BitXorString( xorBits, [Pad= c])

Syntax terms

%resultA string to receive the result of XORing together the bits in string and xorBits.
string One of the strings to be XORed.
xorBits The other string to be XORed.
Pad A single character that indicates the character with which the shorter of the two input strings is to be extended. As many copies of c are used as is required to make the shorter string as long as the longer. If both strings are of equal length, no padding is required. The default value of c is '00':x.

Usage notes

  • Using a null string or xorBits is an easy way of XORing each byte in a string with a specific byte value (the Pad value).
  • BitXorString is most useful for working with binary data, for example binary data being sent or received with Janus Sockets.

Examples

The following example compares the result of BitXorString (logical exclusive OR) versus BitOrString (logical inclusive OR):

b printText {~='Ale':stringToHex} printText {~='Lager':stringToHex} print '======================' printText {~='Ale':bitOrString('Lager', pad='40':x)} printText {~='Ale':bitOrString('Lager', pad='40':x):stringToHex} print '======================' printText {~='Ale':bitXorString('Lager', pad='40':x)} printText {~='Ale':bitXorString('Lager', pad='40':x):stringToHex} end

The result is:

'Ale':stringToHex=C19385 'Lager':stringToHex=D381878599 ====================== 'Ale':bitOrString('Lager', pad='40':x)=LlgER 'Ale':bitOrString('Lager', pad='40':x):stringToHex=D39387C5D9 ====================== 'Ale':bitXorString('Lager', pad='40':x)=???ER 'Ale':bitXorString('Lager', pad='40':x):stringToHex=121202C5D9

See also