Skip to content
Justice Tech School

Bitwise Operators

& | ^ ~ << >> work on bits. Flags enums use them.

Example
int flags = 0;
flags |= 1 << 2;
flags |= 1;
Console.WriteLine(flags);
Console.WriteLine((flags & 4) != 0);
Console.WriteLine(Convert.ToString(flags, 2));

Exercise

Shift left.

1  3

Quiz Test

What does 1 << 3 give?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.