hello everyone. i am new to Lisp. i dont know how to perform binary operations in LISP?
can anyone share sample of code for binary addition or multiplication plz
can anyone share sample of code for binary addition or multiplication plz
Discuss and learn Lisp programming of all dialects
This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.
4 posts · 4771 views
(+ 1 2) ; = 3
(* 2 3) ; = 6(+ 10 #xa #b1010) ; ==> 30
Now when makeing a string out of the number you get to choose the base:(let ((thirty (+ 10 #xa #b1010)))
(format nil "~n ~x ~o ~b" thirty thirty thirty thirty))
; ==> "30 1E 36 11110"
There you have it. 30 displayed in 4 different bases. In CL you have the special variable *print-base* which sets the default base in which numbers are printed and *read-base* which sets the default base in which numbers are read when parsed:(let ((*print-base* 16)
(*read-base* 2))
(princ (read-from-string "1011"))) ; ==> B
Thats about all there is to know about displaying and parsing numbers. Now all your base are belong to you