Set bits preserved2Rotation preserves the number of 1 bits.
How it is calculated
For a word of width w, normalize the nonnegative count: n = count mod w. If n = 0, return the unchanged bit pattern. ROL = ((x << n) OR (x >> (w − n))) AND mask. ROR = ((x >> n) OR (x << (w − n))) AND mask, where mask = 2^w − 1 and x is the unsigned bit pattern. Signedness changes how decimal input and output are interpreted; the circular bit movement is the same. This is a rotation without carry, not an arithmetic shift, text rotation, or geometric rotation. Supported widths: 8, 16, 32 and 64. Counts are whole numbers from 0 to 1 trillion; negative counts are rejected. Prefixes must match the selected input base. In signed decimal mode, input must fit the signed range; other bases may specify a positive raw bit pattern.
Bit Rotation Calculator
CalcsDecoded.com
Result
3
8-bit unsigned decimal after ROL.
Bits leaving one end re-enter at the other. The dashed cells identify wrapped bits; this operation does not use a carry flag.
Result breakdown
Measure
Result
Binary
00000011
Hexadecimal
0x03
Signed decimal
3
Effective rotation
1 bit1 modulo 8 = 1.
Set bits preserved
2Rotation preserves the number of 1 bits.
Inputs used
Rotation direction: Rotate left (ROL)
Word size: 8 bits
Integer to rotate: 129
Rotation count: 1
Input base: 10
Interpretation: Unsigned
Method and assumptions
For a word of width w, normalize the nonnegative count: n = count mod w. If n = 0, return the unchanged bit pattern. ROL = ((x << n) OR (x >> (w − n))) AND mask. ROR = ((x >> n) OR (x << (w − n))) AND mask, where mask = 2^w − 1 and x is the unsigned bit pattern. Signedness changes how decimal input and output are interpreted; the circular bit movement is the same. This is a rotation without carry, not an arithmetic shift, text rotation, or geometric rotation. Supported widths: 8, 16, 32 and 64. Counts are whole numbers from 0 to 1 trillion; negative counts are rejected. Prefixes must match the selected input base. In signed decimal mode, input must fit the signed range; other bases may specify a positive raw bit pattern.
Examples and assumptions
Rotate a finite bit pattern left or right. Bits wrap around the word; signedness changes decimal interpretation, not the circular bit movement.
8-bit rotate left
3 = 00000011 = 0x03.
129 is 10000001. Rotate left by one: the leading 1 wraps into bit 0, producing 00000011.
8-bit rotate right
192 = 11000000 = 0xC0.
The trailing 1 wraps into bit 7. The remaining bits move right by one.
Count larger than the word
3; effective rotation 1 bit.
9 modulo 8 is 1. One full turn restores the original word; the remaining step produces 00000011.
Before you use the result
Supported word sizes are 8, 16, 32 and 64. Inputs must fit the selected signed or unsigned interpretation. Matching binary, octal and hexadecimal prefixes follow the input base.
Counts are nonnegative whole numbers from 0 to 1 trillion and are normalized modulo word size. Zero and full turns return the unchanged pattern. Negative counts are rejected; select the opposite direction instead.
This tool rotates without carry. It does not simulate processor flags, rotate-through-carry instructions, text rotation or geometric rotation. Exact instruction count rules may differ by language or processor.
Calculation checks and references
Independent string-rotation references verify every 8-bit pattern at counts 0–16, plus cases for all supported widths, both directions and signedness modes, inverse rotations, large counts, count normalization and preservation of set bits. Existing programmer arithmetic and bitwise references are rerun.
Reference cases checked: . Checks are automated reference calculations; an independent professional review is not claimed.
References explain definitions, rules or context; they do not endorse CalcsDecoded.com. See our calculation methodology for the testing and updating standard.
Frequently asked questions
How is rotation different from shifting?
Rotation returns bits leaving one end to the other end. A logical shift inserts zeros and may discard bits. Rotation preserves the number of set bits.
What if the rotation count is larger than the word size?
The count is reduced modulo the selected width. For 8 bits, 9 steps is equivalent to 1; 8 steps leaves the pattern unchanged.
Does signed mode change how bits rotate?
No. It changes the accepted decimal input range and decimal result interpretation. The same two’s-complement pattern moves in the same circle.
Does this rotate through the carry flag?
No. ROL/ROR here rotate only the selected word. No carry flag or CPU instruction state is modeled.
Report a problem or send feedback
Report a problem or send feedback
Tell us what went wrong or how we can improve this calculator. Please don't include financial or other sensitive information.