Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 54 / 68

Bitwise operations (bitwAnd, bitwOr, bitwXor, shifts)

This lesson covers the basics of bitwise operations in R, 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. What is distinctive in R is that these come as the functions bitwAnd(), bitwOr(), bitwXor(), and bitwShiftL().

The sample code shows the results of each on the integers 12 and 10, plus bitwShiftL(a, 2), which shifts two bits left (multiplying by four). Unlike the & and | of other languages, R provides these as functions.

A common early stumble is simply adjusting to that function form if you are used to the symbolic notation elsewhere.

In professional work, these rarely come up in everyday statistics, 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 R 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)