Bit Shift Operation

Shift bits of an integer left or right

Bit Shift Calculator

Bitwise Shifting

This function shifts the bits of an integer left or right. Left means multiplication, right means division by powers of two.

Example: 10100110 (binary) = 166 (dec) = A6 (hex)
Number of shift positions
Results of Bit Shift Operation
Binary:
Octal:
Decimal:
Hexadecimal:

Bit-Shift Visualization

Example: 10100110 << 2 (Left Shift)
Original: 1 0 1 0 0 1 1 0 (166)
After 2 Left: 1 0 0 1 1 0 0 0 (664)
Shift to the left
166 × 2² = 166 × 4 = 664
Left Shift
(<<)

Multiplication

n << k = n × 2^k

Zeros from right
Right Shift
(>>)

Division

n >> k = n ÷ 2^k

Zeros from left
Logical Shift
  • Shifted-out bits are discarded
  • Zeros are shifted in (regardless of direction)
  • No sign handling
  • Ideal for unsigned numbers

Mathematical Foundations of Bit Shifting

Bit shifting is a fundamental operation that has a mathematical relationship to powers of 2:

Left Shift
\[n \ll k = n \times 2^k\]

Each position to the left corresponds to multiplication by 2

Right Shift
\[n \gg k = \lfloor n \div 2^k \rfloor\]

Each position to the right corresponds to division by 2 (rounded down)

Bit Shift Formulas and Examples

General Shift Formulas
\[\text{Left: } n \ll k = n \times 2^k\]
\[\text{Right: } n \gg k = \lfloor n \div 2^k \rfloor\]

n = starting value, k = number of shift positions

Step-by-Step Example: 10100110 << 2

Original: 10100110₂ = 166₁₀

Operation: Left shift by 2 positions

Calculation: 166 × 2² = 166 × 4 = 664

Binary Shift:

10100110 → 101001100 → 1010011000

Result: 1010011000₂ = 664₁₀ = 298₁₆

Right Shift Example: 10100110 >> 2

Original: 10100110₂ = 166₁₀

Operation: Right shift by 2 positions

Calculation: ⌊166 ÷ 2²⌋ = ⌊166 ÷ 4⌋ = ⌊41.5⌋ = 41

Binary Shift:

10100110 → 01010011 → 00101001

Result: 00101001₂ = 41₁₀ = 29₁₆

More Shift Examples
8 << 3 (Left Shift):
Original: 00001000₂ (8)
Result: 01000000₂ (64)
Math: 8 × 2³ = 8 × 8 = 64
100 >> 2 (Right Shift):
Original: 01100100₂ (100)
Result: 00011001₂ (25)
Math: ⌊100 ÷ 4⌋ = 25

Shift Reference

Standard Example
10100110 << 2 = 1010011000 166 × 4 = 664 Left = Multiplication
Powers of Two

2⁰ = 1

2¹ = 2

2² = 4

2³ = 8

2⁴ = 16

2⁵ = 32

2⁶ = 64

2⁷ = 128

Shift Operators

<<: Left shift (multiplication)

>>: Right shift (division)

Logical: Fill with zeros

Arithmetic: Preserve sign

Circular: Bits rotate

Common Applications

Fast multiplication: n << k

Fast division: n >> k

Create bit masks: (1 << n) - 1

Alignment: (addr + 7) >> 3 << 3

Bitwise Shifting - Detailed Description

Bitwise Shifting

In bitwise shifting, the binary digits are shifted by a specified number of bit positions to the left or right. The direction specification is always understood in the standard convention of the binary system, regardless of computer architecture: left means multiplication and right means division by a power of two.

Basic Principle:
• Left shift: Multiplication by 2^n
• Right shift: Division by 2^n
• Very fast operation
• Bits are shifted out and filled in

Registers and Hardware

Processor registers contain a defined finite number of bits, which is why the specified number of bits are "shifted out" at one end of the register, while the same number are "shifted in" ("pulled in") at the other end.

Hardware Implementation

1. Bits are physically shifted
2. Empty positions are filled
3. Overflowing bits are lost
4. Operation occurs in one clock cycle

Logical Shifting

In the logical shifting used here, the shifted-out bits are discarded and zeros are filled in, regardless of the shift direction. Unlike arithmetic shifts, signed numbers cannot be used.

Logical Shift:
• Always fill with zeros
• No sign handling
• Suitable for unsigned numbers
• Simple implementation

Mathematical Applications

Bit shifting is one of the most efficient methods for multiplication and division by powers of two. It is frequently used in systems programming, graphics processing, and performance-critical applications.

Performance Benefits
  • Extremely fast (1 clock cycle)
  • No expensive multiplications/divisions
  • Ideal for powers of 2
  • Often optimized by compiler

Practical Bit Shift Examples

Array Indexing

Scenario: 4-byte alignment

Index: 5

Address: 5 << 2 = 20

Effect: index × 4 (faster than *4)

Bit Masks

Scenario: Create n-bit mask

Operation: (1 << n) - 1

Example: (1 << 4) - 1 = 15

Result: 00001111₂ (4-bit mask)

Memory Alignment

Scenario: 8-byte alignment

Address: 0x12345678

Alignment: (addr + 7) >> 3 << 3

Result: Next 8-byte boundary

Programming Tips
  • Fast multiplication: n << k instead of n * (1<
  • Division by 2^n: value >> n
  • Check bit position: (value >> bit) & 1
  • Watch overflow: Bits are lost
  • Compiler optimization: x*8 → x<<3
  • Portability: Consider shift behavior


IT Functions

Decimal, Hex, Bin, Octal conversionShift bits left or rightSet a bitClear a bitBitwise ANDBitwise ORBitwise exclusive OR

Special functions

AiryDerivative AiryBessel-IBessel-IeBessel-JBessel-JeBessel-KBessel-KeBessel-YBessel-YeSpherical-Bessel-J Spherical-Bessel-YHankelBetaIncomplete BetaIncomplete Inverse BetaBinomial CoefficientBinomial Coefficient LogarithmErfErfcErfiErfciFibonacciFibonacci TabelleGammaInverse GammaLog GammaDigammaTrigammaLogitSigmoidDerivative SigmoidSoftsignDerivative SoftsignSoftmaxReLUSoftplusSwishStruveStruve tableModified StruveModified Struve tableRiemann Zeta

Hyperbolic functions

ACoshACothACschASechASinhATanhCoshCothCschSechSinhTanh

Trigonometrische Funktionen

ACosACotACscASecASinATanCosCotCscSecSinSincTanDegree to RadianRadian to Degree