RosettaCodeData/Task/Bitwise-operations/Common-Lisp/bitwise-operations-2.lisp

10 lines
326 B
Common Lisp

(defun shl (x width bits)
"Compute bitwise left shift of x by 'bits' bits, represented on 'width' bits"
(logand (ash x bits)
(1- (ash 1 width))))
(defun shr (x width bits)
"Compute bitwise right shift of x by 'bits' bits, represented on 'width' bits"
(logand (ash x (- bits))
(1- (ash 1 width))))