RosettaCodeData/Task/Bitwise-operations/Common-Lisp/bitwise-operations-3.lisp
2016-12-05 22:15:40 +01:00

13 lines
578 B
Common Lisp

(defun rotl (x width bits)
"Compute bitwise left rotation of x by 'bits' bits, represented on 'width' bits"
(logior (logand (ash x (mod bits width))
(1- (ash 1 width)))
(logand (ash x (- (- width (mod bits width))))
(1- (ash 1 width)))))
(defun rotr (x width bits)
"Compute bitwise right rotation of x by 'bits' bits, represented on 'width' bits"
(logior (logand (ash x (- (mod bits width)))
(1- (ash 1 width)))
(logand (ash x (- width (mod bits width)))
(1- (ash 1 width)))))