请注意,逻辑运算工作,布尔值,其次,数字为零,NIL不是一样的。
对数位运算
位运算符位工作并进行逐位操作。对于按位与,或,和XOR运算的真值表如下:
pqp and qp or qp xor q
Assume if A = 60; and B = 13; now in binary format they will be as follows: A = 0011 1100 B = 0000 1101 ----------------- A and B = 0000 1100 A or B = 0011 1101 A xor B = 0011 0001 not A = 1100 0011
通过LISP支持位运算符列于下表中。假设变量A=60和变量B=13,则:
操作符描述Example
这将返回位逻辑的参数和。如果没有给出参数,则结果为-1,这是该操作的标识。
这将返回位逻辑包括它的参数或。common lisp如果没有给出参数,那么结果是零,这是该操作的标识。
这将返回其参数的按位逻辑异或。如果没有给出参数,那么结果是零,这是该操作的标识。
这不返回的逐位它的参数。如果没有给出参数,则结果为-1,这是该操作的标识。
这将返回其参数的逐位逻辑相等(也称为异或非)。如果没有给出参数,则结果为-1,这是该操作的标识。
示例
创建一个名为main.lisp一个新的源代码文件,并在其中输入如下代码:
(setq a 60) (setq b 13) (format t "~% BITWISE AND of a and b is ~a" (logand a b)) (format t "~% BITWISE INCLUSIVE OR of a and b is ~a" (logior a b)) (format t "~% BITWISE EXCLUSIVE OR of a and b is ~a" (logxor a b)) (format t "~% A NOT B is ~a" (lognor a b)) (format t "~% A EQUIVALANCE B is ~a" (logeqv a b)) (terpri) (terpri) (setq a 10) (setq b 0) (setq c 30) (setq d 40) (format t "~% Result of bitwise and operation on 10, 0, 30, 40 is ~a" (logand a b c d)) (format t "~% Result of bitwise or operation on 10, 0, 30, 40 is ~a" (logior a b c d)) (format t "~% Result of bitwise xor operation on 10, 0, 30, 40 is ~a" (logxor a b c d)) (format t "~% Result of bitwise eqivalance operation on 10, 0, 30, 40 is ~a" (logeqv a b c d))
当您单击Execute按钮,或按下Ctrl+ E,LISP立即执行它,返回的结果是:
BITWISE AND of a and b is 12 BITWISE INCLUSIVE OR of a and b is 61 BITWISE EXCLUSIVE OR of a and b is 49 A NOT B is -62 A EQUIVALANCE B is -50 Result of bitwise and operation on 10, 0, 30, 40 is 0 Result of bitwise or operation on 10, 0, 30, 40 is 62 Result of bitwise xor operation on 10, 0, 30, 40 is 60 Result of bitwise eqivalance operation on 10, 0, 30, 40 is -61
标签:运算符
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创优秀实例教程
本文标题:LISP - 运算符
本文地址:
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-26738-3.html
我有去看