Intermediate

Bit Rotate Calculator (Circular Shift)

Perform a circular bit rotation (barrel shift) of an integer left or right within an 8, 16, 32, or 64-bit register.
Non-negative integer that fits in the chosen width

bits

Direction

Bit width

Rotated value (binary)
10010110
Decimal
150
Binary
10010110
Hex
0x96
Effective shift
3
031.963.895.6127.5159.4191.3223.1255Before and after rotation in the 8-bit range
Step by step
  1. 1

    Effective rotate amount

    3 mod 8 = 3
  2. 2

    Rotate left

    (210 << 3) | (210 >> (8 − 3)) = 150
    Bits leaving one end reappear at the other; result masked to 8 bits.
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

A bit rotate, or circular shift, moves every bit of an integer left or right by k positions inside a w-bit register, wrapping bits off one end back onto the other. Reduce k by k mod w, then OR the shifted value with the wrapped bits and mask to w bits. Output appears in decimal, binary, and hex.

Formula
ROL: r = ((n << k) | (n >> (w − k))) & mask; ROR: r = ((n >> k) | (n << (w − k))) & mask; mask = (1 << w) − 1
How this is calculated

A rotation (also called a circular or barrel shift) moves every bit of the value n by k positions inside a register of fixed width w. Unlike a plain shift, bits pushed off one end are not discarded — they re-enter at the opposite end, so the total number of set bits never changes. Choose the width (8, 16, 32, or 64) that matches the register you are modelling; n must be non-negative and fit within that width.

The calculator first reduces the rotate amount with k mod w, because rotating by the full width returns the original value. A rotate left combines (n << k) with the bits that wrapped around, (n >> (w − k)), then masks the result with (1 << w) − 1 to keep only the low w bits. A rotate right is the mirror image, using (n >> k) and (n << (w − k)). All arithmetic is done with arbitrary-precision integers (BigInt) so 64-bit values stay exact.

The output is shown in decimal, as a zero-padded w-bit binary string, and in hexadecimal padded to the register width. Edge cases: a rotate amount that is a multiple of w leaves the value unchanged, and a value that does not fit in the selected width is rejected. Bit indices in the breakdown are labelled with the most significant bit on the left.

Frequently asked questions

A logical shift discards the bits that fall off the end and fills the vacated positions with zeros. A rotate (circular shift) feeds those bits back in at the other end, so no information is lost and the population count stays the same.

Rotating w times in a w-bit register returns every bit to its original position. The calculator applies k mod w, so a rotate of 8 in an 8-bit register, or 16, 24, and so on, is equivalent to rotating by 0.

The value must be representable in w bits (between 0 and 2^w − 1). If n is larger, widen the register or reduce n; the calculator will not silently truncate it.

Also known as

bit rotate calculator
circular shift
rotate left rotate right
rol ror
barrel rotate bits
bit rotation
circular bit shift

APA

TG we-Calculate Editorial Team. (2026). Bit Rotate Calculator (Circular Shift) [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/bit-rotate-calculator

Chicago

TG we-Calculate Editorial Team. "Bit Rotate Calculator (Circular Shift)." TG we-Calculate. 2026. https://we-calculate.com/calculator/bit-rotate-calculator.

IEEE

TG we-Calculate Editorial Team, "Bit Rotate Calculator (Circular Shift)," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/bit-rotate-calculator

BibTeX

@misc{wecalculate_bit_rotate_calculator, title = {Bit Rotate Calculator (Circular Shift)}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/bit-rotate-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?