Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 54 / 68

Bitwise operations (And, Or, Xor, shifts)

This lesson covers the basics of bitwise operations in VB.NET, with the aim of understanding how to manipulate a number bit by bit.

A bitwise operation works on a number's binary bits. And gives 1 only where both bits are 1, Or where either is, Xor where exactly one is, and << shifts the bits left.

The sample code shows the results of And, Or, and Xor on the integers 12 and 10, plus a << 2, which shifts two bits left (multiplying by four). Thinking in binary makes each operation much clearer.

A common early stumble is confusing the logical AndAlso/OrElse with the bitwise And/Or. Branching uses AndAlso/OrElse; bit-level work uses And/Or/Xor.

In professional work, bitwise operations turn up in low-level data handling — flag management (packing several settings into one number), image processing, cryptography.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)