After going over how values are represented by bits and how numbers are represented in binary and hexadecimal, you can now see operations that change values at bit-level.

Because there is no direct access to individual bits, even though these operations are at bit-level, they affect at least 8 bits at a time. For example, for a variable of type ubyte, a bit operation would be applied to all of the 8 bits of that variable.

As the uppermost bit is the sign bit for signed types, we will ignore signed types and use only uint in the examples below. You can repeat these operations with ubyte, ushort, and ulong; as well as byte, short, int, and long, as long as you remember the special meaning of the uppermost bit.

First, let’s define a function that will be useful later when examining how bit operators work. This function will print a value in binary, hexadecimal, and decimal systems:

Get hands-on with 1200+ tech skills courses.