Function Definitions

19  -  Bitwise

NOTE:  The arguments for each of the following functions must be integers.

logior ..... Returns the result of a logical bitwise "or" of two or more integers

(logior 1 2 3)  returns 3
(logior 2 6)  returns 6
(logior 6 9)  returns 15

  00000001 | 1
  00000010 | 2     00000010 | 2     00000110 |  6
  00000011 | 3     00000110 | 6     00001001 |  9
  ---------|--     ---------|--     ---------|---
  00000011 | 3     00000110 | 6     00001111 | 15


logand ..... Returns the result of a logical bitwise "and" of two or more integers

(logand 1 2 3)  returns 0
(logand 2 6)  returns 2
(logand 15 5 7)  returns 5

  00000001 | 1                      00001111 | 15
  00000010 | 2     00000010 | 2     00000101 |  5
  00000011 | 3     00000110 | 6     00000111 |  7
  ---------|--     ---------|--     ---------|---
  00000000 | 0     00000010 | 2     00000101 |  5 



~ ..... Returns the result of converting binary 1's to 0's and vice versa

(~ 0)  returns -1
(~ 1)  returns -2
(~ 2)  returns -3

Integers in binary code are composed of 32 bits with the top bit determining the sign. This function is the bitwise complement, so
00000000000000000000000000000000 (0)
  has as complement 11111111111111111111111111111111 (-1)
00000000000000000000000000000001 (1)
  has as complement 11111111111111111111111111111110 (-2)
00000000000000000000000000000010 (2)
  has as complement 11111111111111111111111111111101 (-3)


lsh ..... Returns the result of shifting the bits of an integer a specified number of places to the left

(lsh 4 1)  returns 8 (shifting 00000100 1 bit to the left yields 00001000)
(lsh 4 -2)  returns 1 (shifting 00000100 2 bits to the right yields 00000001)
(lsh 13 2)  returns 52 (shifting 00001101 2 bits to the left yields 00110100)
(lsh -9 -1)  returns 2147483643

"0" bits are shifted in. Bits shifted out are discarded. A change in the high (32nd) bit changes the sign of the number.


boole ..... Applies one of 16 Boolean functions to one or more pairs of integers


HOME

Copyright © 1988, 1998 Ronald W. Leigh