Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Bitwise Shift Operators | Introduction to Operators
C++ Introduction

Bitwise Shift OperatorsBitwise Shift Operators

What is a byte

This is a byte, a fundamental unit of digital information storage. A byte consists of 8 bits.

At the core of digital information storage is the byte, composed of 8 bits. Each bit represents a binary digit, and numbers are commonly expressed in the binary system, a base-2 numeral system. The binary representation involves expressing a number as a sum of powers of 2.

Binary Representation Examples

Consider the number 4, which in binary is represented as 00000100. Each bit in this byte corresponds to a power of 2:

0+0+0+0+0+2²+0+0 = 4

Similarly, the number 5 is represented as 00000101:

0+0+0+0+0+2²+0+2⁰ = 5

Bitwise shift

Click👇
  • In this context, a single left bit shift effectively multiplies the value by 2;
  • Conversely, when we execute a single right bit shift, divides the value by 2.

Think of the right and left shift operation >> OR << by n positions as a division by 2^n. In the case of 10 >> 3, it is effectively dividing 10 by 2^3 (which is 8), and the result is 1.

cpp

main.cpp

Note

Try shifting value to the left (<<) or right (>>) by different positions.

Все було зрозуміло?

Секція 3. Розділ 5
course content

Зміст курсу

C++ Introduction

Bitwise Shift OperatorsBitwise Shift Operators

What is a byte

This is a byte, a fundamental unit of digital information storage. A byte consists of 8 bits.

At the core of digital information storage is the byte, composed of 8 bits. Each bit represents a binary digit, and numbers are commonly expressed in the binary system, a base-2 numeral system. The binary representation involves expressing a number as a sum of powers of 2.

Binary Representation Examples

Consider the number 4, which in binary is represented as 00000100. Each bit in this byte corresponds to a power of 2:

0+0+0+0+0+2²+0+0 = 4

Similarly, the number 5 is represented as 00000101:

0+0+0+0+0+2²+0+2⁰ = 5

Bitwise shift

Click👇
  • In this context, a single left bit shift effectively multiplies the value by 2;
  • Conversely, when we execute a single right bit shift, divides the value by 2.

Think of the right and left shift operation >> OR << by n positions as a division by 2^n. In the case of 10 >> 3, it is effectively dividing 10 by 2^3 (which is 8), and the result is 1.

cpp

main.cpp

Note

Try shifting value to the left (<<) or right (>>) by different positions.

Все було зрозуміло?

Секція 3. Розділ 5
some-alt