Operators: &

AND operator.

Syntax

integer‑operand&integer‑operand

rect‑operand&rect‑operand

styles‑operand&styles‑operand

user‑defined‑set‑operand&user‑defined‑set‑operand

Bitwise AND

In its first version, the & operator performs on both operands a bitwise AND operation. If used in combination with 8-, 16- or 32-bit signed integer operands, the data type resulting from the operation is consequently int32. When mixing signed and unsigned integer operands, the operation results in the unsigned uint32 value. In the case, one of the operands is 64-bit large, the resulting data type is int64 or uint64 according to whether the 64-bit operand is signed or unsigned. For example:

var uint32 a = 0xFF003AC0;
var uint32 b = 0xAB15FF70;
var int32  c =  1369;          // = 0x00000559
var int32  d = -1496;          // = 0xFFFFFA28
var uint64 e = 0x1234AB15FF70;
var int64  f = -149613691251;  // = 0xFFFFFFDD2A543E8D

var uint32 result = a & b; // result = 0xAB003A40
var int32  result = c & d; // result = 8
var uint32 result = a & d; // result = 0xFF003A00
var int64  result = a & f; // result = 0x2A003A80
var uint64 result = d & e; // result = 0x1234AB15FA20

Rectangle intersection

In its second version, the & operator performs a rectangle intersection. The result is a new rectangle representing an area contained within the left AND the right rect operand. The operator results in an empty rectangle (isempty) if the both rectangles don't intersect. For example:

var rect a = <10,5,110,220>;
var rect b = <-10,-50,50,75>;
var rect c = <110,5,120,220>;

var rect result = a & b; // result = <10,5,50,75>
var rect result = b & a; // result = <10,5,50,75>
var rect result = a & c; // result = empty rectangle

Please note the operator && containing an alternative, more advanced implementation of the rectangle intersection.

Styles intersection

In its third version, the & operator combines the both styles operands to a new styles value. Please note, styles operands can be considered as collections containing multiple elements you can individually include or exclude. Thus, the & operation results in a new styles value including only those elements which exist in the left AND in the right operand. The resulting data type of the operation is always styles. For example:

var styles a = [ Style1, Style3, Style16 ];
var styles b = [ Style3, Style16 ];
var styles c = [ Style1, Style8 ];

var styles result = a & b; // result = [ Style3, Style16 ]
var styles result = b & c; // result = []

Set intersection

In its fourth version, the & operator combines the both user-defined set operands to a new set value. Please note, set operands can be considered as collections containing multiple elements you can individually include or exclude. Thus, the & operation results in a new set value including only those elements which exist in the left AND in the right operand. The resulting data type of the operation corresponds to the data type of the operands. For example:

var Core::Layout a = Core::Layout[ AlignToTop, ResizeHorz ];
var Core::Layout b = Core::Layout[ ResizeHorz ];
var Core::Layout c = Core::Layout[ AlignToTop, ResizeVert ];

var Core::Layout result = a & b; // result = Core::Layout[ ResizeHorz ]
var Core::Layout result = b & c; // result = Core::Layout[]