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 |
---|---|
1 | bit-andThis is the bitwise “and” operator |
2 | bit-orThis is the bitwise “or” operator |
3 | bit-xorThis is the bitwise “xor” or Exclusive ‘or’ operator |
4 | bit-notThis is the bitwise negation operator |
Following is the truth table showcasing these operators.
p | q | p&q | p | q | p ^ q |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
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
Pingback: Clojure - Logical Operators | Adglob Infosystem Pvt Ltd
Pingback: Clojure - Operators | Adglob Infosystem Pvt Ltd