Clojure – Bitwise Operators

clojure bitwise operators

In this guide, we will discuss Clojure Bitwise Operators. Groovy provides four bitwise operators. Following are the bitwise operators available in Groovy.

Sr.No.Operator & Description
1bit-andThis is the bitwise “and” operator
2bit-orThis is the bitwise “or” operator
3bit-xorThis is the bitwise “xor” or Exclusive ‘or’ operator
4bit-notThis is the bitwise negation operator

Following is the truth table showcasing these operators.

pqp&qp | qp ^ q
00000
01011
11110
10011

The following code snippet shows how the various operators can be used.

Example

(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def x (bit-and 00111100 00001101))
   (println x)
   
   (def x (bit-or 00111100 00001101))
   (println x)
   
   (def x (bit-xor 00111100 00001101))
   (println x)) 
(Example)

The above program produces the following output.

Output

576
37441
36865

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply