Clojure-bitwise-operators

提供:Dev Guides
移動先:案内検索

Clojure-ビット演算子

Groovyは4つのビット演算子を提供します。 以下は、Groovyで使用可能なビットごとの演算子です。

Sr.No. Operator & Description
1

bit-and

これはビット単位の「and」演算子です

2

bit-or

これはビット単位の「or」演算子です

3

bit-xor

これはビット単位の「xor」または排他的な「or」演算子です

4

bit-not

これはビットごとの否定演算子です

以下は、これらの演算子を示す真理値表です。

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

次のコードスニペットは、さまざまな演算子の使用方法を示しています。

(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)

上記のプログラムは、次の出力を生成します。

出力

576
37441
36865