Bitwise AND (&) Expression

Summary

Evaluate with a logical AND 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 AND 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 AND operation will compare each bit. If both bits are 1 (one), the resulting bit is 1 (one); otherwise, the resulting bit is 0 (zero).

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

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

Here is an illustration for the evaluation of the expression 0 & 5:

1
2
3
4
  0001 (1)
  0101 (5)
  ----
= 0001 (1)

Differences from JavaScript

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

Examples

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

See Also

Share

HTML | BBCode | Direct Link