BitAndString (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Full stop)
m (printtext)
Line 20: Line 20:
<li>Using a null <var class="term">string</var> or <var class="term">andBits</var> is an easy way of ANDing 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">andBits</var> is an easy way of ANDing each byte in a string with a specific byte value (the <var class="term">pad</var> value).
<li><var>BitAndString</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>BitAndString</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>BitAndString</var> was introduced in <var class="product">Sirius Mods</var> version 7.9.
<li><var>BitAndString</var> was introduced in <var class="product">[[Sirius Mods|"Sirius Mods"]]</var> version 7.9.
</ul>
</ul>


Line 30: Line 30:


<li>The following example:
<li>The following example:
<p class="pre">printText {~='Red':bitAndString('Green', pad='FF':x)}
<p class="pre">[[PrintText statement|printText]] {~='Red':bitAndString('Green', pad='FF':x)}
</p>
</p>
outputs
outputs
Line 47: Line 47:


==See also==
==See also==
<ul><li>For details of the <var>printtext</var> statement, please see <var>[[Intrinsic classes#printtext|printText]]</var>.</ul>
{{Template:String:BitAndString footer}}
{{Template:String:BitAndString footer}}

Revision as of 11:26, 22 February 2011

Do bitwise And of strings (String class)

[Introduced in Sirius Mods 7.9]


BitAndString does a logical AND of the bits in two strings.

Syntax

%result = string:BitAndString( andBits, [Pad= c])

Syntax terms

%resultA string to receive the result of ANDing together the bits in string and andBits.
string One of the strings to be ANDed.
andBits The other string to be ANDed.
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 pad 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 pad is '00':x.

Usage notes

  • Using a null string or andBits is an easy way of ANDing each byte in a string with a specific byte value (the pad value).
  • BitAndString is most useful for working with binary data, for example binary data being sent or received with Janus Sockets.
  • BitAndString was introduced in "Sirius Mods" version 7.9.

Examples

  1. The following example turns off the low order bit of a numeric value's string representation, rounding every digit down to an even number (because EBCDIC binary digits map 0-9 to hex values X'F0'-X'F9'):

    %evenDigits = %digits:bitAndString(, pad='FE':x)

    In, the above code, if %digits were '31415926', %evenDigits would be set to '20404826'.

  2. The following example:

    printText {~='Red':bitAndString('Green', pad='FF':x)}

    outputs

    'Red':bitAndString('Green', pad='FF':x)=Aaden

    To see why this is correct run the following:

    printText {~='Red':stringToHex} printText {~='Green':stringToHex} printText {~='Red':bitAndString('Green', pad='FF':x):stringToHex}

    which outputs

    'Red':stringToHex=D98584 'Green':stringToHex=C799858595 'Red':bitAndString('Green', pad='FF':x):stringToHex=C181848595

See also