bit-set

added
1.0

ns
clojure.core

type
function

(bit-set x n)

Set bit at index n

                user=> (bit-set 2r1011 2) ; index is 0-based
15 
;; 15 = 2r1111

;; the same in decimal
user=> (bit-set 11 2) 
15
            
                ;; Returns a long, like all Clojure bit operations
user=> (bit-set 0 63)
-9223372036854775808
; A signed 64-bit number with only the sign bit (most significant bit) on.
; This is the most negative number representable by signed 64 bits: -(2**63).
; Same as:
user=> (bit-shift-left 1 63)
-9223372036854775808

;; And in case you forget your common powers to two, here's a reference ^^
user=> (bit-set 0 32)
4294967296
user=> (bit-set 0 16)
65536
user=> (bit-set 0 8)
256
user=> (bit-set 0 4)
16