CharXOR()

CHARXOR()

Combine corresponding ASCII value of two strings with bitwise XOR

Syntax

      CHARXOR( <[@]cString1>, <cString2> ) --> cXOrString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cXOrString> string with bitwise XOR combined ASCII values

Description

The CHARXOR() function constructs a new string from the two strings passed as parameters. To do this, it combines the ASCII values of the corresponding characters of both strings with a bitwise XOR-operation and places a character in the resulting string whose ASCII value equals to the result of that operation. If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      // easy encryption
      ? charxor( "This is top secret !", "My Password" ) // --> <encrypted sentence>

Tests

      charxor( charxor( "This is top secret !", "My Password" ), "My Password" ) == "This is top secret !"

Compliance

CHARXOR() is compatible with CT3’s CHARXOR().

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARNOT(), CHARAND(), CHAROR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharSHR()

CHARSHR()

Process each character in a string with bitwise SHIFT RIGHT operation

Syntax

      CHARSHR( <[@]cString>, <nBitsToSHR> ) --> cSHRString

Arguments

<[@]cString> string to be processed

<nBitsToSHR> number of bit positions to be shifted to the right

Returns

<cSHRString> string with bitwise shifted right characters

Description

The CHARSHR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT RIGHT (SHR) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLR() function instead. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charshr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(0)+Chr(0)+Chr(0)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Tests

      charshr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 ) 
      == Chr(0)+Chr(0)+Chr(0)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Compliance

CHARSHR() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARRLL(), CHARRLR(), CSETREF()

CharSHL()

CHARSHL()

Process each character in a string with bitwise SHIFT LEFT operation

Syntax

      CHARSHL( <[@]cString>, <nBitsToSHL> ) --> cSHLString

Arguments

<[@]cString> string to be processed

<nBitsToSHL> number of bit positions to be shifted to the left

Returns

<cSHLString> string with bitwise shifted left characters

Description

The CHARSHL() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT LEFT (SHL) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLL() function instead. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charshl( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(0)+Chr(0)+Chr(0)

Tests

      charshl( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
       == Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(0)+Chr(0)+Chr(0)

Compliance

CHARSHL() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharRLR()

CHARRLR()

Process each character in a string with bitwise ROLL RIGHT operation

Syntax

      CHARRLR( <[@]cString>, <nBitsToRLR> ) --> cRLRString

Arguments

<[@]cString> string to be processed

<nBitsToRLR> number of bit positions to be rolled to the right

Returns

<cRLRString> string with bitwise rolled right characters

Description

The CHARRLR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise ROLL RIGHT (RLR) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that, in contrast to CHARSHR(), bits rolled out on the right are put in again on the left. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charrlr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Tests

      charrlr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
       == Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Compliance

CHARRLR() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARSHR(), CHARRLL(), CSETREF()

CharRLL()

CHARRLL()

Process each character in a string with bitwise ROLL LEFT operation

Syntax

      CHARRLL( <[@]cString>, <nBitsToRLL> ) --> cRLLString

Arguments

<[@]cString> string to be processed

<nBitsToRLL> number of bit positions to be rolled to the left

Returns

<cRLLString> string with bitwise rolled left characters

Description

The CHARRLL() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise ROLL LEFT (RLL) operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. Be aware that, in contrast to CHARSHL(), bits rolled out on the left are put in again on the right. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charrll( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)

Tests

      charrll( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 ) 
        == Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)

Compliance

CHARRLL() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARNOT(), CHARSHL(), CHARSHR(), CHARRLR(), CSETREF()

CharOr()

CHAROR()

Combine corresponding ASCII value of two strings with bitwise OR

Syntax

      CHAROR( <[@]cString1>, <cString2> ) --> cOrString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cOrString> string with bitwise OR combined ASCII values

Description

The CHAROR() function constructs a new string from the two strings passed as parameters. To do this, it combines the ASCII values of the corresponding characters of both strings with a bitwise OR-operation and places a character in the resulting string whose ASCII value equals to the result of that operation. If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      // set the LSB
      ? charor( "012345678", chr( 1 ) ) // --> "113355779"
      ? charor( "012345678", chr( 1 ) + chr( 3 ) ) // --> "133357779"

Tests

      charor( "012345678", chr( 1 ) ) == "113355779"
      charor( "012345678", chr( 1 ) + chr( 3 ) ) == "133357779"

Compliance

CHAROR() is compatible with CT3’s CHAROR().

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARNOT(), CHARAND(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharNot()

CHARNOT()

Process each character in a string with bitwise NOT operation

Syntax

      CHARNOT( <[@]cString> ) --> cNotString

Arguments

<[@]cString> string to be processed

Returns

<cNotString> string with bitwise negated characters

Description

The CHARNOT() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise NOT operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. It can be easily seen that the resulting ASCII-value equals 255 minus input ASCII value. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charnot( chr( 85 ) + chr( 128 ) + chr( 170 ) + chr( 1 ) ) 
// --> chr( 170 ) + chr( 127 ) + chr( 85 ) + chr( 254 ) ? charnot( charnot( "This is a test!" ) ) --> "This is a test!"

Tests

      charnot( chr( 85 ) + chr( 128 ) + chr( 170 ) + chr( 1 ) ) ==;
chr( 170 ) + chr( 127 ) + chr( 85 ) + chr( 254 ) charnot( charnot( "This is a test!" ) ) == "This is a test!"

Compliance

CHARNOT() is compatible with CT3’s CHARNOT().

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()