Bitwise operators

TypeScript supports the following bitwise operators. To understand the examples, you must assume that variable A holds 2 as value and variable B holds 3 as value:

Operator

Description

Example

&

Known as the bitwise AND operator, it performs a boolean AND operation on each bit of its integer arguments.

(A & B) is 2

|

Known as the bitwise OR operator, it performs a boolean OR operation on each bit of its integer arguments.

(A | B) is 3.

^

Known as the bitwise XOR operator, it performs a boolean exclusive OR operation on each bit of its integer arguments. Exclusive OR means that either operand one is true or operand two is true, but not both.

(A ^ B) is 1.

~

Known as the bitwise NOT operator, ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.