Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applications of a circular shift

I would like to know some examples of application of circular shifts. For example, a right shift on an unsigned integer would result in a division by two. Conversely, a left shift would result in a multiplication by 2. Are there any famous/interesting properties of a circular shift on binary numbers.

Note: The example about the right/left shift is to illustrate an application of that particular operator. I am asking for similar examples for the circular shift operator/function.

like image 233
Mike G Avatar asked Dec 19 '22 21:12

Mike G


1 Answers

One surprising place where circular shifts show up is in the Josephus survivor problem. In this slightly morbid problem, n people stand in a circle. The first person kills the second, then the third kills the fourth, etc. This process repeats where one person kills the next until only one person is left. The question is given n people, which person survives?

Amazingly, the answer is given by doing a right circular shift on n by one bit. There's a great proof of this in Graham, Knuth, and Patashnik's book Concrete Mathematics.

Hope this helps!

like image 131
templatetypedef Avatar answered Jan 08 '23 06:01

templatetypedef