Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 54 / 68

Bitwise operations (AND, OR, XOR, shifts)

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

A bitwise operation treats a number as binary and calculates digit by digit. There are & (AND), | (OR), xor(), and << (left shift), used commonly for permission flags and low-level work.

The sample code shows the results of &, |, and xor(a, b) on the integers 12 and 10, plus a << 2, which shifts two bits left (multiplying by four). Note that XOR alone comes as a function.

A common early stumble is exactly that. The ^ symbol is Julia's exponentiation operator, so XOR needs the xor() function instead.

In professional work, these rarely come up in everyday data analysis, but they are useful knowledge when low-level data handling is needed.

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

๐Ÿงช This site can't compile or run Julia 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)