store/[org.clojure/clojure "1.8.0"] clj::clojure.core/bit-shift-left

Official Documentation

Add notes
Arities
==================================================
   [x n]

Docstring
==================================================
  Bitwise shift left

Source

(defn bit-shift-left
  "Bitwise shift left"
  {:inline (fn [x n] `(. clojure.lang.Numbers (shiftLeft ~x ~n)))
   :added "1.0"}
  [x n] (. clojure.lang.Numbers shiftLeft x n))

Example 1

Edit
;;a bogus bit-array implementation

(def ba (atom (long 0)))

(defn set-ba 
  "sets bit n in long atom ba"
  [n]
  (let [number-set (bit-shift-left 1 n)
        _          (println "number to set: " number-set)
        new-array  (bit-or @ba number-set)]
    (reset! ba new-array)))

(defn get-ba 
  "gets bit n in long atom ba"
  [n]
  (not (zero? (bit-and (bit-shift-left 1 n) @ba))))

(comment
  (set-ba 0) ;; 0 [....0001]
  (set-ba 3) ;; 2^3 = 8  [....1001]
  (get-ba 0) ;; (bit-and ba 2^0) = 1
  (get-ba 1) ;; (bit-and ba 2^1) = 0
  (get-ba 3) ;; (bit-and ba 2^3) = 1
  ;;but:
  (set-ba 65) ;; [....1011]
  ;;number to set:  2
  ;;modulo because long has only 64 bit
  ;;also note that long always is two-complemented (signed) in java implementation
)

Example 2

Edit
(bit-shift-left 2r1101 2) ; fill rightmost bits with 0s
;; => 52 
;; 52 = 2r110100

Uses on crossclj