► 1 ACL2
 ▼ 1.4 Functions and Macros
 1.4.1 Booleans 1.4.2 Symbols 1.4.3 Strings 1.4.4 Characters 1.4.5 Rational and Complex Arithmetic 1.4.6 Bitwise Operations 1.4.7 Ordinal Arithmetic 1.4.8 Lists 1.4.9 Association Lists 1.4.10 Sets 1.4.11 Trees 1.4.12 Sequences 1.4.13 IO
Version: 4.1.4
##### 1.4.6Bitwise Operations

 (ash x y) → t x : (integerp x) y : (integerp y)

Multiplies x by 2^y. This is equivalent to shifting the binary representation of x to the left by y bits.

 Examples: > (ash 1 3) 8 > (ash 5 2) 20 > (ash '5 2) 20

 (logand x ...)
 (logior x ...)
 (logxor x ...)
 (logeqv x ...)

Bitwise logical operations on numbers. These forms compute the bitwise AND, inclusive OR, exclusive OR, and equivalence (a.k.a. exclusive NOR), respectively. These macros expand into calls of binary functions such as binary-logand, binary-logior, etc. The guards of these functions require that all inputs be integers. When passed one argument, these functions return the argument unchanged. When passed no arguments, logand and logeqv return -1, while logior and logxor return 0.

 Examples: > (logand) -1 > (logior) 0 > (logxor) 0 > (logeqv) -1 > (logand 1) 1 > (logand 10 6) 2 > (logior 10 5) 15 > (logxor 15 9) 6 > (logeqv 5 6) -4 > (logior "5") "5"

 (lognand x y) → t x : (integerp x) y : (integerp y)

Computes the bitwise logical NAND of the two given numbers.

 Examples: > (lognand 10 6) -3

 (lognor x y) → t x : (integerp x) y : (integerp y)

Computes the bitwise logical NOR of x and y.

 Examples: > (lognor 10 6) -15

 (lognot x) → t x : (integerp x)

Computes the bitwise logical NOT of the given number.

 Examples: > (lognot 5) -6

 (logbitp i j) → t i : (and (integerp i) (>= i 0)) j : (integerp j)

Returns the ith bit in the two’s complement binary representation of j.

 Examples: > (logbitp 3 15) t > (logbitp 3 16) () > (logbitp 0 1) t

 (logcount x) → t x : (integerp x)

Returns the number of "on" bits in the binary representation of x.

 Examples: > (logcount -1) 0 > (logcount 4) 1 > (logcount 7) 3

 (logorc1 x y) → t x : (integerp x) y : (integerp y)

Computes the bitwise logical Inclusive OR of y with the bitwise logical NOT of x.

 Examples: > (logorc1 10 6) -9

 (logorc2 x y) → t x : (integerp x) y : (integerp y)

Computes the bitwise logical Inclusive OR of x with the bitwise logical NOT of y.

 Examples: > (logorc2 10 6) -5

 (logtest x y) → t x : (integerp x) y : (integerp y)

Returns true if and only if x and y share a ’1’ bit somewhere in their binary representation (i.e. (logand x y) is not zero).

 Examples: > (logtest 4 15) t > (logtest 4 16) ()