Circularly Rotate Text to the Left
Circularly rotate text to the left by N positions. Supports character-level and word-level rotation with step-by-step visualization.
About
Circular left rotation shifts every character (or word) in a string by n positions toward the beginning. Characters that fall off the left edge wrap around to the right end. The operation is equivalent to taking the substring from index n mod L and concatenating the prefix before it. A rotation of n = 0 or n = L returns the original string unchanged. Incorrect rotation in cryptographic ciphers, data serialization, or circular buffer implementations causes silent data corruption that propagates downstream.
This tool computes the rotation in O(L) time using native string slicing. It supports both character-level and word-level modes. Note: word-level rotation treats consecutive whitespace as a single delimiter and discards extra spaces. Pro tip: rotating by L − n positions to the left is identical to rotating n positions to the right.
Formulas
The circular left rotation of a string S of length L by n positions is defined as:
The effective rotation index k is computed as:
Where R = resulting rotated string, S = original input string, L = length of string (character count or word count depending on mode), n = number of positions to rotate left, k = effective rotation after modulo reduction. When k = 0, the output equals the input. The operation forms a cyclic group of order L under composition.
Reference Data
| Original String | Rotation (n) | Mode | Result |
|---|---|---|---|
| ABCDEF | 0 | Character | ABCDEF |
| ABCDEF | 1 | Character | BCDEFA |
| ABCDEF | 2 | Character | CDEFAB |
| ABCDEF | 3 | Character | DEFABC |
| ABCDEF | 6 | Character | ABCDEF |
| ABCDEF | 8 | Character | CDEFAB |
| Hello World | 3 | Character | lo WorldHel |
| one two three four | 1 | Word | two three four one |
| one two three four | 2 | Word | three four one two |
| one two three four | 4 | Word | one two three four |
| A | 5 | Character | A |
| AB | 1 | Character | BA |
| rotate me | 7 | Character | merotate |
| alpha beta gamma | 3 | Word | alpha beta gamma |
| a b c d e | 3 | Word | d e a b c |