Bitwise operations in Common Lisp
One could argue it is highly suspect to do low-level bit-twiddling operations in a language such as Common Lisp. But as hairy as that may sound, it is actually very doable in a high level language with arbitrary precision arithmetics. And since Common Lisp is one of my favourite languages, I tend to consider using it for almost any kind of open-ended, experimental programming.
As it happens, I just had the need to implement some of these operations. Once I got them working, I spotted that they are missing from the corresponding page on Rosetta Code, so I decided to publish them. They have been tested pretty heavily, so I’m quite confident they are correct.
Below is a copy of the material I submitted here.
Left and right logical shift may be implemented by the following functions:
Left and right rotation may be implemented by the following functions: