ArticleslgStudy

mathematics

Circular shift

Circular shift is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Circular shift rather than just read about it. In short: In combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation. A circular shift is a special kind of cyclic permutation, which in turn is a special kind of permutation.

Circular shift — main illustration
Circular shift — illustration

Key takeaways

  • Circular shift belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Circular shift to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Circular shift from memory before moving on to harder problems.

Reference excerpt

In combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation. A circular shift is a special kind of cyclic permutation, which in turn is a special kind of permutation. Formally, a circular shift is a permutation σ of the n entries in the tuple such that either

σ(i)≡(i+1) modulo n, for all entries i = 1, ..., n or

σ(i)≡(i−1) modulo n, for all entries i = 1, ..., n. The result of repeatedly applying circular shifts to a given tuple are also called the circular shifts of the tuple. For example, repeatedly applying circular shifts to the four-tuple (a, b, c, d) successively gives

(d, a, b, c), (c, d, a, b), (b, c, d, a), (a, b, c, d) (the original four-tuple), and then the sequence repeats; this four-tuple therefore has four distinct circular shifts. However, not all n-tuples have n distinct circular shifts. For instance, the 4-tuple (a, b, a, b) only has 2 distinct circular shifts. The number of distinct circular shifts of an n-tuple is nk, where k is a divisor of n, indicating the maximal number of repeats over all subpatterns. In computer programming, a bitwise rotation, also known as a circular shift, is a bitwise operation that shifts all bits of its operand. Unlike an arithmetic shift, a circular shift does not preserve a number's sign bit or distinguish a floating-point number's exponent from its significand. Unlike a logical shift, the vacant bit positions are not filled in with zeros but are filled in with the bits that are shifted out of the sequence.

Implementing circular shifts Circular shifts are used often in cryptography in order to permute bit sequences. Unfortunately, many programming languages, including C, do not have operators or standard functions for circular shifting, even though virtually all processors have bitwise operation instructions for it (e.g. Intel x86 has ROL (Rotate Left) and ROR (Rotate Right)). However, some compilers may provide access to the processor instructions by means of intrinsic functions. In addition, some constructs in standard ANSI C code may be optimized by a compiler to the "rotate" assembly language instruction on CPUs that have such an instruction. Most C compilers recognize the following idiom, and compile it to a single 32-bit rotate instruction.

This safe and compiler-friendly implementation was developed by John Regehr, and further polished by Peter Cordes. A simpler version is often seen when the count is limited to the range of 1 to 31 bits:

This version is dangerous because if the count is 0 or 32, it asks for a 32-bit shift, which is undefined behaviour in the C language standard. However, it tends to work anyway, because most microprocessors implement value >> 32 as either a 32-bit shift (producing 0) or a 0-bit shift (producing the original value), and either one produces the correct result in this application.

Example If the bit sequence 0001 0111 were subjected to a circular shift of one bit position... (see images below)

If the bit sequence 1001 0110 were subjected to the following operations:

Applications Cyclic codes are a kind of block code with the property that the circular shift of a codeword will always yield another codeword. This motivates the following general definition: For a string s over an alphabet Σ, let shift(s) denote the set of circular shifts of s, and for a set L of strings, let shift(L) denote the set of all circular shifts of strings in L. If L is a cyclic code, then shift(L) ⊆ L; this is a necessary condition for L being a cyclic language. The operation shift(L) has been studied in formal language theory. For instance, if L is a context-free language, then shift(L) is again context-free. Also, if L is described by a regular expression of length n, there is a regular expression of length O(n3) describing shift(L).

See also Barrel shifter Circulant Lyndon word Necklace — an object like a tuple but for which circular shifts are considered equivalent.

References

Illustrations

Circular shift illustration
Circular shift illustration
Circular shift: Enciphering a letter of the latin alphabet with a key of value 26k, where k is a relative integer, leads to a circular shift of |k| full turns.
Enciphering a letter of the latin alphabet with a key of value 26k, where k is a relative integer, leads to a circular shift of |k| full turns.
Circular shift: Left circular shift.
Left circular shift.
Circular shift: Right circular shift.
Right circular shift.

Worked examples

Example 1 — a first encounter with Circular shift

Start with the simplest possible case. Write down what Circular shift claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Circular shift before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Circular shift ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Circular shift

In research
Circular shift appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Circular shift in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Circular shift is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer arithmetic, Elementary mathematics, so understanding it makes those chapters shorter.
In everyday life
Look for Circular shift outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Circular shift” →

How to study Circular shift in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Circular shift means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Circular shift out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Circular shift in simple terms?

In combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation. A circular shift is a special kind of cyclic…

Why does Circular shift matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Circular shift?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Circular shift.

Tags

  • Computer arithmetic
  • Elementary mathematics

Keep exploring