目录

Show 例子

Groovy提供了四个按位运算符。 以下是Groovy中可用的按位运算符。

Sr.No. 操作符和说明
1

bit-and

这是按位“和”运算符

2

bit-or

这是按位“或”运算符

3

bit-xor

这是按位“xor”或“Exclusive”或“运算符”

4

bit-not

这是按位否定运算符

以下是展示这些运算符的真值表。

p q p&Q p | q p ^ q
00000
01011
11110
10011

以下代码段显示了如何使用各种运算符。

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

上述程序产生以下输出。

输出 (Output)

576
37441
36865
↑回到顶部↑
WIKI教程 @2018