On this page:
ash
logand
logior
logxor
logeqv
lognand
lognor
lognot
logbitp
logcount
logorc1
logorc2
logtest
Version: 4.1
2.4.6 Bitwise 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 binary 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 binary 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")

  /Users/cce/plt/research/dracula/release/src/language/primiti

  ve-procedures/acl2-prims-scheme.scm:38:28: Dracula program

  broke the contract (case-> (-> any) (-> integer?

  any) (-> integer? integer? any) (-> integer? integer?

  integer? any) (-> (listof integer?) any)) on here;

  expected <integer?>, given: "5"

  > (logxor 1/2 2)

  /Users/cce/plt/research/dracula/release/src/language/primiti

  ve-procedures/acl2-prims-scheme.scm:38:28: Dracula program

  broke the contract (case-> (-> any) (->* () (listof

  integer?) any)) on here; expected <(listof integer?)>,

  given: (1/2 2)

(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

  > (lognand 1/2 2)

  /Users/cce/plt/research/dracula/release/src/language/primiti

  ve-procedures/acl2-prims-scheme.scm:38:28: Dracula program

  broke the contract (case-> (-> any) (-> integer?

  any) (-> integer? integer? any) (-> integer? integer?

  integer? any) (-> (listof integer?) any)) on here;

  expected <integer?>, given: 1/2

(lognor x y)  t

  x : (integerp x)

  y : (integerp y)

Computes the bitwise logical NOR of x and y.

Examples:

  > (lognor 10 6)

  -15

  > (lognor 1/2 2)

  /Users/cce/plt/research/dracula/release/src/language/primiti

  ve-procedures/acl2-prims-scheme.scm:38:28: Dracula program

  broke the contract (case-> (-> any) (-> integer?

  any) (-> integer? integer? any) (-> integer? integer?

  integer? any) (-> (listof integer?) any)) on here;

  expected <integer?>, given: 1/2

(lognot x)  t

  x : (integerp x)

Computes the bitwise logical NOT of the given number.

Examples:

  > (lognot 5)

  -6

  > (lognot "5")

  /Users/cce/plt/research/dracula/release/src/language/checkin

  g-proc.scm:36:21: Dracula program broke the contract (->

  integer? any) on here; expected <integer?>, given: "5"

(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

  > (logbitp -1 3)

  ()

(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

  > (logcount 1/2)

  0

(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

  > (logorc1 1/2 10)

  /Users/cce/plt/research/dracula/release/src/language/checkin

  g-proc.scm:36:21: Dracula program broke the contract (->

  integer? integer? any) on here; expected <integer?>, given:

  1/2

  > (logorc1 1)

  eval:1192:0: logorc1: Expected 2 arguments, but got 1 in:

  (logorc1 1)

(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

  > (logorc2 1/2 10)

  /Users/cce/plt/research/dracula/release/src/language/checkin

  g-proc.scm:36:21: Dracula program broke the contract (->

  integer? integer? any) on here; expected <integer?>, given:

  1/2

  > (logorc2 1)

  eval:1201:0: logorc2: Expected 2 arguments, but got 1 in:

  (logorc2 1)

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

  ()