xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

ˆˆ

Bitwise XOR operator (binary): performs a logical XOR operation.

Syntax

<cString> ˆˆ <nMask>|<cMask> --> cCharacter

<nNumber> ˆˆ <nMask>|<cMask> --> nNumeric

Arguments

<cString>
A character expression of which all bits of each character are processed in a logical XOR operation.
<nNumber>
A numeric value all bits of which are processed. Numbers are always treated as integer values. If a number has a decimal fraction, it is truncated.
<nMask>|<cMask>
The right operand of the bitwise XOR operator can be specified as a character or a numeric value.

Description

The bitwise XOR operator performs a logical XOR operation with the individual bits of both operands. The left operand is the value to process while the right operand provides the bit mask for the operation. The return value of the &-operator has the same data type as the left operand.

Bits at identical positions in both operands are compared. The bit at the same position is set in the return value, when both operands have the bit set differently at the same position. If both operands have the same bit set or not set, i.e. when both bits are the same, the corresponding bit in the return value is not set.

A special feature of a logical XOR operation is that the left operand can be recovered from the result value when the result value is XORed with the right operand in a second operation.

The bit mask to apply to the left operand can be specified as a numeric or as a character value. Depending on the left operand, bitwise XOR operations are performed according to the following rules:

cString ˆˆ cMask

When both operands are character values, the bits of individual characters of both operands are compared. If the right operand has less characters, it is repeatedly applied until all characters of the left operand are processed. The return value has the same number of characters as the left operand.

cString ˆˆ nMask

When the left operand is a character value and the right operand is numeric, the bits set in the numeric value are compared with the bits of each character in the left operand.

nNumber ˆˆ cMask

When the left operand is numeric and the right operand is a character value, the bits set in the numeric value are compared consecutively with the bits of each character in the right operand.

nNumber ˆˆ nMask

When both operands are numeric values, the bits of both values are compared.

Note:  Numeric operands are always treated as integer values. If a number has a decimal fraction, it is ignored.

Info

See also:& (bitwise AND), | (bitwise OR), .AND., .NOT., .OR., HB_BitXOr()
Category: Bitwise operators , Operators , xHarbour extensions
LIB:xhb.lib
DLL:xhbdll.dll

Example

// This example encrypts and decrypts the value 'Secure sentence.'
// with a key 'Secret password'.

   PROCEDURE MAIN()
      LOCAL cEncrypted := "Secure sentence." ˆˆ "Secret password"
      LOCAL cDecrypted := cEncrypted ˆˆ "Secret password"

      ? cEncrypted
      ? cDecrypted
   RETURN NIL

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe