manpagez: man pages & more
info cln
Home | html | info | man
 [ << ] [ < ] [ Up ] [ > ] [ >> ] [Top] [Contents] [Index] [ ? ]

### 4.9.1 Logical functions

Integers, when viewed as in two’s complement notation, can be thought as infinite bit strings where the bits’ values eventually are constant. For example,

```    17 = ......00010001
-6 = ......11111010
```

The logical operations view integers as such bit strings and operate on each of the bit positions in parallel.

`cl_I lognot (const cl_I& x)`
`cl_I operator ~ (const cl_I& x)`

Logical not, like `~x` in C. This is the same as `-1-x`.

`cl_I logand (const cl_I& x, const cl_I& y)`
`cl_I operator & (const cl_I& x, const cl_I& y)`

Logical and, like `x & y` in C.

`cl_I logior (const cl_I& x, const cl_I& y)`
`cl_I operator | (const cl_I& x, const cl_I& y)`

Logical (inclusive) or, like `x | y` in C.

`cl_I logxor (const cl_I& x, const cl_I& y)`
`cl_I operator ^ (const cl_I& x, const cl_I& y)`

Exclusive or, like `x ^ y` in C.

`cl_I logeqv (const cl_I& x, const cl_I& y)`

Bitwise equivalence, like `~(x ^ y)` in C.

`cl_I lognand (const cl_I& x, const cl_I& y)`

Bitwise not and, like `~(x & y)` in C.

`cl_I lognor (const cl_I& x, const cl_I& y)`

Bitwise not or, like `~(x | y)` in C.

`cl_I logandc1 (const cl_I& x, const cl_I& y)`

Logical and, complementing the first argument, like `~x & y` in C.

`cl_I logandc2 (const cl_I& x, const cl_I& y)`

Logical and, complementing the second argument, like `x & ~y` in C.

`cl_I logorc1 (const cl_I& x, const cl_I& y)`

Logical or, complementing the first argument, like `~x | y` in C.

`cl_I logorc2 (const cl_I& x, const cl_I& y)`

Logical or, complementing the second argument, like `x | ~y` in C.

These operations are all available though the function

`cl_I boole (cl_boole op, const cl_I& x, const cl_I& y)`

where `op` must have one of the 16 values (each one stands for a function which combines two bits into one bit): `boole_clr`, `boole_set`, `boole_1`, `boole_2`, `boole_c1`, `boole_c2`, `boole_and`, `boole_ior`, `boole_xor`, `boole_eqv`, `boole_nand`, `boole_nor`, `boole_andc1`, `boole_andc2`, `boole_orc1`, `boole_orc2`.

Other functions that view integers as bit strings:

`bool logtest (const cl_I& x, const cl_I& y)`

Returns true if some bit is set in both `x` and `y`, i.e. if `logand(x,y) != 0`.

`bool logbitp (const cl_I& n, const cl_I& x)`

Returns true if the `n`th bit (from the right) of `x` is set. Bit 0 is the least significant bit.

`uintC logcount (const cl_I& x)`

Returns the number of one bits in `x`, if `x` >= 0, or the number of zero bits in `x`, if `x` < 0.

The following functions operate on intervals of bits in integers. The type

```struct cl_byte { uintC size; uintC position; };
```

represents the bit interval containing the bits `position``position+size-1` of an integer. The constructor `cl_byte(size,position)` constructs a `cl_byte`.

`cl_I ldb (const cl_I& n, const cl_byte& b)`

extracts the bits of `n` described by the bit interval `b` and returns them as a nonnegative integer with `b.size` bits.

`bool ldb_test (const cl_I& n, const cl_byte& b)`

Returns true if some bit described by the bit interval `b` is set in `n`.

`cl_I dpb (const cl_I& newbyte, const cl_I& n, const cl_byte& b)`

Returns `n`, with the bits described by the bit interval `b` replaced by `newbyte`. Only the lowest `b.size` bits of `newbyte` are relevant.

The functions `ldb` and `dpb` implicitly shift. The following functions are their counterparts without shifting:

`cl_I mask_field (const cl_I& n, const cl_byte& b)`

returns an integer with the bits described by the bit interval `b` copied from the corresponding bits in `n`, the other bits zero.

`cl_I deposit_field (const cl_I& newbyte, const cl_I& n, const cl_byte& b)`

returns an integer where the bits described by the bit interval `b` come from `newbyte` and the other bits come from `n`.

The following relations hold:

• `ldb (n, b) = mask_field(n, b) >> b.position`,
• `dpb (newbyte, n, b) = deposit_field (newbyte << b.position, n, b)`,
• `deposit_field(newbyte,n,b) = n ^ mask_field(n,b) ^ mask_field(new_byte,b)`.

The following operations on integers as bit strings are efficient shortcuts for common arithmetic operations:

`bool oddp (const cl_I& x)`

Returns true if the least significant bit of `x` is 1. Equivalent to `mod(x,2) != 0`.

`bool evenp (const cl_I& x)`

Returns true if the least significant bit of `x` is 0. Equivalent to `mod(x,2) == 0`.

`cl_I operator << (const cl_I& x, const cl_I& n)`

Shifts `x` by `n` bits to the left. `n` should be >=0. Equivalent to `x * expt(2,n)`.

`cl_I operator >> (const cl_I& x, const cl_I& n)`

Shifts `x` by `n` bits to the right. `n` should be >=0. Bits shifted out to the right are thrown away. Equivalent to `floor(x / expt(2,n))`.

`cl_I ash (const cl_I& x, const cl_I& y)`

Shifts `x` by `y` bits to the left (if `y`>=0) or by `-y` bits to the right (if `y`<=0). In other words, this returns `floor(x * expt(2,y))`.

`uintC integer_length (const cl_I& x)`

Returns the number of bits (excluding the sign bit) needed to represent `x` in two’s complement notation. This is the smallest n >= 0 such that -2^n <= x < 2^n. If x > 0, this is the unique n > 0 such that 2^(n-1) <= x < 2^n.

`uintC ord2 (const cl_I& x)`

`x` must be non-zero. This function returns the number of 0 bits at the right of `x` in two’s complement notation. This is the largest n >= 0 such that 2^n divides `x`.

`uintC power2p (const cl_I& x)`

`x` must be > 0. This function checks whether `x` is a power of 2. If `x` = 2^(n-1), it returns n. Else it returns 0. (See also the function `logp`.)

 [ << ] [ < ] [ Up ] [ > ] [ >> ] [Top] [Contents] [Index] [ ? ]

This document was generated on August 27, 2013 using texi2html 5.0.

```© manpagez.com 2000-2018