Bitwise XOR (^) Expression

Summary

Evaluate with a logical exclusive OR operation.

Syntax

expression1 ^ expression2

Parameters

expression1
Any legal Boolean or numeric expression.
expression2
Any legal Boolean or numeric expression.

Description

For numeric and Boolean expressions, the ^ operator computes the values of the operands, converts them to equal-length binary representations, performs a logical exclusive OR operation on them, and returns the evaluated result. For example, the decimal (base 10) number 0 (zero) may be converted to the binary form 0000 and the number 1 (one) may be converted to 0001. The bitwise XOR operation will compare each bit. If both bits are 0 (zero), the resulting bit is 0 (zero); if both bits are 1 (one), the resulting bit is 0 (zero); if either bit is 1 (one) and the opposite bit is 0 (zero), the resulting bit is 1 (one).

For example, here is an illustration of the evaluation of the expression 0 ^ 1:

1
2
3
4
  0000 (0)
  0001 (1)
  ----
= 0001 (1)

Here is an illustration for the evaluation of the expression 3 ^ 5:

1
2
3
4
  0011 (3)
  0101 (5)
  ----
= 0110 (6)

Differences from JavaScript

Logical XOR operations are not limited to 32-bit integers in JS++. Unimplemented In JavaScript, the logical XOR operation is limited to signed 32-bit integers.

Examples

Basic Usage
1
2
3
4
5
import System;
 
Console.log(0 ^ 0); // 0
Console.log(0 ^ 1); // 1
Console.log(1 ^ 5); // 4

See Also

Share

HTML | BBCode | Direct Link