Bitwise operators in MSP
What kind of situation will I ever use these operators (I'm new to programing) in MSP? The help and reference files don't really shed any light on how any of these objects would work in practical situations. Sorry if this is a general question. Just a little curious.
Sub Avian Flow wrote on Sat, 01 August 2009 02:11What kind of situation will I ever use these operators (I'm new to programing) in MSP? The help and reference files don't really shed any light on how any of these objects would work in practical situations. Sorry if this is a general question. Just a little curious.
You will use them when you need them.
Many people use them all the time.
I always have people in my Max courses who ask "what do I need modulo for?" When I explain about using it to extract pitch class information ("how do I know if a C is hit--it can be middle C, or the 'cello C two ledger lines below bass clef, or C on top of the 5th ledger above violin clef, or *any* C), about half of them get it. The other half come back a week later and ask "how can I recognize if a C is hit--any C).
Bit operations are useful for things like recognizing chords. How that is done is left as an exercise for the reader.
Modulo is a great thing (I just discovered it's usefulness a few months ago, when trying to figure out how to turn a 16 bit number into two 8 bit numbers for sending controller data to pro tools)
But, I still have no clue what the difference between the bitwise and regular and/or objects (bitand, if X || y vs if x | y, etc) is.
Also, the << and >> seem useful (just looked them up) but I've almost never had to multiply/divide something by a power of two (which strikes me as weird that I haven't).
one thing about "bitwise" is that a bitshift of 1 requires
less CPU than a calculation of [*~ 10.] but returns the
same result.
but i must say i dont really use it. it is quite rare in DSP
world and more something for building logic, i.e. for messages.
-110
p.s. and oh yeah, "chord regonition", yes you can also use
binary stuff for encoding multiple stages.
1 of (1-16) = true
and
2 of (1-16) = true
and
5 of (1-16) = true
would require 3 steps in decimal.
converted to binary such a register would read like this:
1 of (1-10000) = true
10 of (1-10000) = true
101 of (1-10000) = true
you can now add those numbers as if they were decimal:
1+10+101=112
and 112 still contains 1,2, and 5 - it can not be some other
combination.
if you now want to compare registers, its only one calculation.
great for realtime.
for a similar thing look into the flags of some older max
objects, they also use such an encoding - actually 1^n -
so that a number of 9 represents 1 and 8, which is 1^1
and 1^4 and means flags 1 and 4 are true.
Hi,
Roman Thilenius wrote on Sun, 02 August 2009 16:21one thing about "bitwise" is that a bitshift of 1 requires
less CPU than a calculation of [*~ 10.] but returns the
same result.
[<< 1] is the same as multiplying by 2. On integers, but that doesn't work with floating points.
here is an example where I used bitwise operators recently :
(inside the [p asciiToUTF8])
Charles
Quote:
[<< 1] is the same as multiplying by 2.
and that was not the only misleading info in my
hastily fabricated post above.
Thanks guys. I figured as much that bitwise operators are most useful for logic programming. I think I will be much more likely to use the max bitwise operators rather than the MSP objects. At least for now.
It's MATH! It's inherently abstract. Someone in the class always says "What the &%^%W# am I ever going to use this for!" "I hate graphing!" "I hate imaginary numbers! "
And there are ALWAYS word problems to follow.