Polyglot: Concepts
    Overview
    Concepts
    Compile Time and Runtime
    Build Tools
    Numerics
    Memory Management
    Zero Cost Abstractions
    Design Patterns
    Compatibility
    Functional Programming
    Bit Manipulation
    Generics
    String Interning
Polyglot: Language Notes

Programming Languages - Bit Manipulation

Updated: 2021-12-05

AND(&)

| AND | 0   | 1   |
| --- | --- | --- |
| 0   | 0   | 0   |
| 1   | 0   | 1   |

OR(|)

| OR  | 0   | 1   |
| --- | --- | --- |
| 0   | 0   | 0   |
| 1   | 0   | 1   |

XOR(^)

| XOR | 0   | 1   |
| --- | --- | --- |
| 0   | 0   | 0   |
| 1   | 0   | 1   |

NOT(!)

| NOT |     |
| --- | --- |
| 0   | 1   |
| 1   | 0   |

Basic Operations

Bitwise And: &

int bitmask = 0x000F;
int val = 0x2222;

System.out.println(val & bitmask);
// 2

Bitwise exclusive OR: ^

Bitwise inclusive OR: |

Unary bitwise complement: ~

System.out.println(~256);
// -257

Signed left shift: <<

Signed right shift: >>

Unsigned right shift: >>>