[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] small questions on bitwise and asBinaryDigits



pitches == 0100

so you have

0100 & 0000 = 0
0100 & 0001 = 0
0100 & 0010 = 0
0100 & 0011 = 0
0100 & 0100 = 4
0100 & 0101 = 4
0100 & 0110 = 4
0100 & 0111 = 4

What was the desired output?

I basically wanted to get the integer in bits, preferably in the way asBinaryDigits returns it. I think I still  need to do some reading on this, its (/me is) getting quite confused.


IIRC bitwise operators work only on integers, but the result of ** is always a float.

(2**2).dump
   Float 4.0   40100000 00000000
4

So you should do (2**i).asInteger or, more efficient, (1 << i) which is a bitwise shift.

8.do({ |i| (1 << i).postln });
1
2
4
8
16
32
64
128

that  is what I wanted, did not know about the problem with Floats. I guess its because Floats a differently structured than Integers. Thanks a lot though :)


Karsten