&
Prev | Orchestra Opcodes and Operators | Next

## &

& — Bitwise AND operator.

## Description

The bitwise operators perform operations of bitwise AND, bitwise OR, bitwise NOT and bitwise non-equivalence.

## Syntax

    a & b  (bitwise AND)

where the arguments a and b may be further expressions. They are converted to the nearest integer to machine precision and then the operation is performed.

## Performance

The priority of these operators is less binding that the arithmetic ones, but more binding that the comparisons.

Parentheses may be used as above to force particular groupings.

## Examples

Here is an example of the bitwise AND and OR operators. It uses the file bitwise.csd.

Example 31. Example of the bitwise operators.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>

    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2

    instr 1
    iresultOr = p4 | p5
    iresultAnd = p4 & p5
    prints "%i | %i  = %i\\n", p4, p5, iresultOr
    prints "%i & %i  = %i\\n", p4, p5, iresultAnd
    endin

    instr 2 ; decimal to binary converter
    Sbinary = ""
    inumbits = 8
    icount init inumbits - 1

    pass:

    	ivalue = 2 ^ icount
    	if (p4 & ivalue >= ivalue) then
    		Sdigit = "1"
    	else
    		Sdigit = "0"
    	endif
    	Sbinary strcat Sbinary, Sdigit

    loop_ge icount, 1, 0, pass

    Stext sprintf "%i is %s in binary\\n", p4, Sbinary
    prints Stext
    endin

    </CsInstruments>
    <CsScore>
    i 1 0 0.1  1  2
    i 1 +  .   1  3
    i 1 +  .   2  4
    i 1 +  .   3  10

    i 2 2  .    12
    i 2 +  .    9
    i 2 +  .    15
    i 2 +  .    49

    e
    </CsScore>
    </CsoundSynthesizer>

## See Also

|, #, ¬

Prev | Up | Next
>> | Home | |