Search code examples
clojure

Printing the binary value of a number in clojure


We can represent the number 12 as 2r001100 in clojure.

Is there a built-in function to print 2r001100 when given the number 12?


Solution

  • see cl-format

    user=> (require '[clojure.pprint :refer (cl-format)])
    nil
    user=> (cl-format nil "2r~6,'0',B" 12)
    "2r001100"