| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
</CsOptions> |
| 4 |
<CsInstruments> |
| 5 |
|
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 2 |
| 9 |
|
| 10 |
instr 1 |
| 11 |
iresultOr = p4 | p5 |
| 12 |
iresultAnd = p4 & p5 |
| 13 |
prints "%i | %i = %i\\n", p4, p5, iresultOr |
| 14 |
prints "%i & %i = %i\\n", p4, p5, iresultAnd |
| 15 |
endin |
| 16 |
|
| 17 |
|
| 18 |
instr 2 ; decimal to binary converter |
| 19 |
Sbinary = "" |
| 20 |
inumbits = 8 |
| 21 |
icount init inumbits - 1 |
| 22 |
|
| 23 |
pass: |
| 24 |
|
| 25 |
ivalue = 2 ^ icount |
| 26 |
if (p4 & ivalue >= ivalue) then |
| 27 |
Sdigit = "1" |
| 28 |
else |
| 29 |
Sdigit = "0" |
| 30 |
endif |
| 31 |
Sbinary strcat Sbinary, Sdigit |
| 32 |
|
| 33 |
loop_ge icount, 1, 0, pass |
| 34 |
|
| 35 |
Stext sprintf "%i is %s in binary\\n", p4, Sbinary |
| 36 |
prints Stext |
| 37 |
endin |
| 38 |
|
| 39 |
</CsInstruments> |
| 40 |
<CsScore> |
| 41 |
i 1 0 0.1 1 2 |
| 42 |
i 1 + . 1 3 |
| 43 |
i 1 + . 2 4 |
| 44 |
i 1 + . 3 10 |
| 45 |
|
| 46 |
i 2 2 0.1 12 |
| 47 |
i 2 + . 9 |
| 48 |
i 2 + . 15 |
| 49 |
i 2 + . 49 |
| 50 |
|
| 51 |
e |
| 52 |
</CsScore> |
| 53 |
</CsoundSynthesizer> |