### Help with simple bit of (binary?) mathematics

A drummer plays a basic groove for one bar, then plays a variation in bar two. In bar three she goes back to the basic groove, then plays a different variation in bar four. Then she reapeats all of the above for the fifth to seventh bars, playing a new variation in bar eight… and so on.

If we tabulate this so far, labelling the bars from one to eight and the variations as 0, 1 and 2, then we get this;

bar var bin

1 0 0001

2 1 0010

3 0 0011

4 2 0100

5 0 0101

6 1 0110

7 0 0111

8 3 1000

What is the formula (or patch) which would allow one to calculate which variation to play based on the bar number? The only insight I have so far is that if you write out the bar numbers in binary as in the third column, then the number of the variation is given by where the rightmost ‘1’ is; in other words, in bar 7 the rightmost ‘1’ is in the 0th column = var 0, in bar 8, the rightmost ‘1’ is in the 3rd column = var 3.

I’ve been messing around with all sorts of stuff, and I just can’t get it; I know the answer to this must be some *really simple* bit of maths which I just can’t see…

Thanks

Probably something with [zl] could do it, based upon the position of the 1. But you could also look to [&] which can turn decimals into binary, by running the number through

& 128

& 64

& 32

etc… collect them all, it will give you the binary version of all numbers up to 255. Not sure if this will help for what you want, but it might… :)

You can either use [bitlist] from the Jasch library or any other way of generating a binary representation from an integer and then use [zl sub]. Here’s an example.

lh

-- Pasted Max Patch, click to expand. --Copyallof the following text. Then, in Max, selectNew From Clipboard.----------begin_max5_patcher---------- 705.3oc4W1taaBCEF92jqBKTmTqTZG1lOLSa+XWGqcS.wKwS7k.iZVp589v1 PSS2hAFDPSSQBhOfse4wu9X6mVYXFlsmVZB9.3K.CimVYXHCIBXzT1vLIXeT bPo70LixRRnoby0pmwo64x3eDv2wJAkTdY8+nfXVBiC3Y.zWIfOAPNtsU46Y o7R1ApnZPzcVMgSqRXow0UWFuIXd.OZGKc62JnQbkLwHq55.fPr7FQVRDC7P SkXajJJK7G2dRmlFjH6TyOWvBhMO1uYU71N1RD74UqDWV2SjT2Bgzh11S0X7 elSU50jInEvLLHcq4KZbjP.BIhOaWewUGsH.6OTFf9aX.8w5N62bEGhAaKxp xOKbDjYXTA0IUftRf3f0gEzBRENHr9G6rPQZUVe7tvAMwNGen3JgnCQ1CEQ3 oCQUGX.Bv5xgHc1HkyoICisqNFQVPFQ2mW.thgd+04YOdM596WeECdyMuCc9 YaSFhTocgXG4ManNFM3DPv+MRB65oX.o6jv19Kb5l3NmIM0XgHsFXzcNZvx7 jEdorFH+9XMvKn03V.TKWlp7EM7vysGdB6YIcwY2uRYLKhpAKS5NVZ3hiszm 3o0m37ey93ZnBF0813rcWVpTVENWdERyhrR33fzREuEjJgLdLqjeVnHe3DuX iZG+X8am0ZLIVjsXs1Se6wkkhRD+TRUlUUD09I2bfCvQcsgVxYoAbVV5qdG6 SeocrManxm2hkD1l7r5DyMZ.h7DoRgDoanN6ZaAvC+wwy9pUwYF6VrCSqiTR hdC0ghDpFN.54q.lZe9XH7kRSfVgcnUxrSutFOQyphH8b7b9Tj+zyHHwW5oT qr2NaUTZrim8Jah675w7t.Zx2RtWQj+wDbxBSA+5ZJ5a9ft37qOSREmVXN0j SezzLuRfaezjy7pIqKvp6iUS8ZQbqQno5BOu5W.M9lnd -----------end_max5_patcher-----------

That’s nice, thanks, that’s kind of the solution I was stumbling towards. Can’t help thinking there must be a much simpler answer, though.

maybe somthing like this?

-- Pasted Max Patch, click to expand. --Copyallof the following text. Then, in Max, selectNew From Clipboard.----------begin_max5_patcher---------- 608.3oc0W10aaCBEF9ZmeEHKsqVZFe5OlTuX+NlplbRXsLEiihIpYqp+2mAr ay5ZlIwXblhDQ9X33WdLmWCOMKJdY0AdcL3yfuBhhdZVTjIjNPT60QwkEGVs on1zsXI+wpk+Hdt8VJ9AkI7GAntXeuRppE+hqiivKfsgk6KExMbkIM31fh0l Q2jwavviSfrnzjf3urSTrI90bTsW0kDTazsEpUOHj2+sc7UJ6bghSadv.Ljo +ifWvzWr.BtqcL1zn94Vtc.wBYyPuSeymmMS2L2UfrubIe24L4Q+8jGkctSd 7om7jLpdVmB0sLnED8M2mChWVHueDYv1c7ZtTUnDUxiUadl4cTpQzv1lWDau jKwmjK2tdIEENzMV0SHlGqmXHCXvT33WO89.41aAvgRD5HPDjwngvbaohOIh BHz+FpyC4bgB4e47X3PNQ2RSbt74n+7IgpeTzHQ.9bPD4cPDxiqa5rXrzgQ6 mQSfkbBwJqzKyRF5QKYFw.JT1jaI+A.cfFP4d0+wxkD5T4Heyf+DUlG4A1t+ ADK+5XGempzxt0BLL4hJsR8XkE0ZAgRYSck0mFbkUh+O6.hk8+wYGX9bCvPr cY.c5cawCc6dif6R1kedRSWi2Hju871lGmN9eBo5p86V0kstCHCd8ItlWqDR i+xQcRuWE.9kN8fX8Zt49cTqTrdaUi3ZEwIdk4plRbPRuQ2isjzGkteLQBql HNnorvKITORJI7RB2ijxCqjPtrXJvXh4pOP.0jqRBENIQcQSrfhobWjD85SR g0A2IC7fpHW9LW5UWA2PVa2bwyy9M.3hBBL -----------end_max5_patcher-----------

you could probably do some conditional processing based on bit masking, but im not totally sure on the best way to do this based on the data you have here..

also depends if you’d like to leave room for your system to grow or not, as if you only need it to handle 8 bars and it’ll be like this always I’d probably use [% 8] and [sel 2 4 6 8] on the bar number to trigger your patches behaviour, using the last outlet for all other.

Forums > MaxMSP