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()

CharSub()

CHARSUB()

Subtracts corresponding ASCII value of two strings

Syntax

      CHARSUB( <[@]cString1>, <cString2>) --> cSubString

Arguments

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

Returns

<cSubString> string with subtracted ASCII values

Description

The CHARSUB() function constructs a new string from the two strings passed as parameters. To do this, it subtracts the ASCII values of the corresponding characters of both strings and places a character in the resulting string whose ASCII value equals to that difference (modulo 256). 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

      ? charsub( "012345678", Chr( 1 ) ) // --> "/01234567"
      ? charsub( "123456789", Chr( 255 ) ) // --> "23456789:"
      ? charsub( "9999", Chr( 0 ) + Chr( 1 ) + Chr( 2 ) + Chr( 3 ) ) // --> "9876"

Tests

      charsub( "123456789", Chr( 1 ) ) == "012345678"
      charsub( "123456789", Chr( 1 ) + Chr( 2 ) ) == "002244668"
      charsub( "012345678", Chr( 255 ) ) == "123456789"
      charsub( "012345678", Chr( 255 ) + Chr( 254 ) ) == "133557799"

Compliance

CHARSUB() 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(), CHARAND(), CHARNOT(), CHAROR(), CHARXOR(), 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()

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()

CharAnd()

CHARAND()

Combine corresponding ASCII value of two strings with bitwise AND

Syntax

      CHARAND( <[@]cString1>, <cString2> ) --> cAndString

Arguments

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

Returns

<cAndString> string with bitwise AND combined ASCII values

Description

The CHARAND() 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 AND-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

      // clear the LSB
      ? charand( "012345678", chr( 254 ) ) // --> "002244668"
      ? charand( "012345678", chr( 254 ) + chr( 252 ) ) // --> "002044648"

Tests

      charand( "012345678", chr( 254 ) ) == "002244668"
      charand( "012345678", chr( 254 ) + chr( 252 ) ) == "002044648"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

CharAdd()

CHARADD()

Adds corresponding ASCII value of two strings

Syntax

      CHARADD( <[@]cString1>, <cString2> ) --> cAddString

Arguments

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

Returns

<cAddString> string with added ASCII values

Description

The CHARADD() function constructs a new string from the two strings passed as parameters. To do this, it adds the ASCII values of the corresponding characters of both strings and places a character in the resulting string whose ASCII value equals to that sum (modulo 256). 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

      ? charadd( "012345678", chr( 1 ) ) // --> "123456789"
      ? charadd( "123456789", chr( 255 ) ) // --> "012345678"
      ? charadd( "0000", chr( 0 ) + chr( 1 ) + chr( 2 ) + chr( 3 ) )
                  // --> "0123"

Tests

      charadd( "012345678", chr( 1 ) ) == "123456789"
      charadd( "012345678", chr( 1 ) + chr( 2 ) ) == "133557799"
      charadd( "123456789", chr( 255 ) ) == "012345678"
      charadd( "123456789", chr( 255 ) + chr( 254 ) ) == "002244668"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

Harbour All Functions – C

CD / CHDIR / DirChange

CDoW

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CLIPINIT
CMonth

Col

Cos

CosH

CountLeft
CountRight

CToBit

CToD

CToDoW
CToF
CToMonth
CToN

CurDir

CSetArgErr
CSetAtMuPa
CSetRef
CTCExit
CTCInit
CTExit
CTInit