Binary in Max?
I want to send binary numbers in form of messages as opposed to a listed message.
I find it kind of hard because if zeroes are first its treated as a number with unnecessary 0 digits.
maybe using combine?
(not sure if this is really what you want)
----------begin_max5_patcher---------- 678.3oc4W9taaBCD.+yvSgkk12XQ9O.wYenR6EXu.qUUlD2TWELHiSa1p569 .aXIMqj3lVHcaBIjN6iym+cG9N+XX.LqXinBB9B36fffGCCBrC0LPPqb.Lmu Y9JdkUMnR7PQ1cvH2TFwFic3OAHciUxMyuUpVdsVL23LMAgmjDAHX1DTDfRZ Dvylf.W09MxEVqTa4OiS6LzMEJihmKrS8UsjuB7MtVW7PmBEqMqDFyOJEtkA JU0KXmMUqykp54s9MYGaVI+o8Cv3Zu4255LlUYb2NQKpDJC2HKTOa2flP1tc Psu.W07UOEF17JZPwYhyAvrTO3YxGddFyZ2NzyDOY3ISabfjodvy3O77Lk53 4T74gmTTa.kj3AOomeddJfYcdlPe7y7hm0ffDaPnWDP7FAkbc8zFg9Zghmsx pH5P3IB.y3pk8fI7qASjS.S4hpJ9Rwej.cIDiQnKgG.f3onF.RIrcH3zdHH5 zShNaYPu7uVyKxyjJAP5d7npJK1hF5AywXuA.E0KjhG57mdfzEW.vGmLdUeL 8uyiedSbwm5bI+GxEepW8uc4JF63kqdepVcSgNmaWb5Yn9k0bvU0Gzt2sern oY7mCyph054c9UWMavV7rPTYjJamX6nzy04V4hEB0tLXgrpAKVzhdwnp2tSp GtCazbGe7l8b4AkNIdRG7Abmb4hxh5TxptKgMydoAhMeydIFTqz1E5caG3yF Xuc4fBzXOAJ4U.zY31qsLy0VShqiuZoA.nTe.Z7nATeNMASGu3K0y3K0+3Ks t4c2srSb80Srw2FoAH95CPGOd5CNGu+d84vjw6vYlOo9nib3betiqNOur7dg tp0lVOot8n6JzMhoQVQoxIZao.pE2K6z21eBjqqaYxT2uzZsqgmMrTXXy57T 3ufwKFdX -----------end_max5_patcher-----------
If you need leading zeros, just put your number into double quotes in a message box. Also, if you want to convert 101 (int) into "00000101" (symbol) you can use [sprintf @symout %08d]. Just keep in mind that it is not a good idea generating large amounts of symbols, you’ll waste memory and slow down Max. If you need more info, there are plenty of forum discussions about this.
Also (but I’m probably stating the obvious here) losing leading zeros in binary representation is harmless, just as it is in decimal: 101 and 00000101 are exactly the same.
EDIT: it’s not [sprintf @symout %08d]. It’s [sprintf symout %08d]!
i meant something like this:
----------begin_max5_patcher---------- 507.3oc4VFsaaCBEF9Z6mBDR6NuHCK1IYWs8BrWfsoJRLKkJavBvodqpu6CN DxbZQotUa8hUqXr33CmyOe9.j6xyvaUibCF8QzWQYY2kmkAl7FxN1OC2wF20 xLfa3Ntwv1ywEg2Y4iVvdYzhnA5q1dy6IKiF6Y1cWKj6uRy2YCoa4lEkEHJo x+npz2RVsnD88iC4GJoUx53Pz9rVvZQego0paiwTNzoFrsbKHLxjgYD+BFFg 3hZvbvS6O64griwmRjKNBYLLTus6yy8MEyDIR9stY6iHhlumO1i9l6pA8Iyv ViUXGrbvhIAt1bAZQHABUSgGKWAvq7h7JMnpRAJ5E.UwCtSCNxK.bOmZo5mr ThTU+FnTxbVoz6RgppYTGQB0QUj+GpizrFgZuVMzmfFzKQiUKWT4l+TX4DYs ucMcBLRWXzyzN.Y45q3R11VXF9bqNhwRX4cQui1h3Lh3Cr1g3tzNE9memBci v3ERSRe9aSTxLpupdi.TX.3Vg7gmhBrwa+bJaTC5cwYxwEqSSK2sxVxrBkbh Ot89PjS9bsnogKmhnohsL4W64pFxLTy4J9eoZlCa17poFelnOgZ7+imWoOUy QNzWHbBU0r99Cbs4XHAg31k3Fk12st.5JjgtvJM24TGDQ++.Xgoc6PXcaOLn CmnLttFm6yy84+1qTdFy -----------end_max5_patcher-----------
I need the code to operate a set of switches, so "0101" means switch 1 is off. "101" means switch 1 is 1 and there is no data for switch 4.
I’m avoiding sprintf/combine/tosymbol just to avoid having symbols and clogging memory
I’d set up addresses for each switch, and then send out the messages like "switch1 1, switch2 0, switch4 1", avoiding that particular type of formatting.
but the question remains; why NOT a list? Because sending out as a list would solve all the problems, as far as I can tell?
I either need to unpack and repack to send this to a sub-patcher (Which gets increasingly annoying with increasing number of switches), I also wish to add flexibility so a "fixed" number of switches kind of limits it (or I need to send all values even if they’re not used at all times – redundancy). Using this I can have one inlet, dynamic creation of objects based on wordlength and neatly transfer everything on one unpack-pack outlet.
It’s just something I wish I had :-)
so you need a nibble-sized packet? that’s not possible, as the smallest data type in max is an int… but what are these switches? are they inside max or somewhere else? if it’s in max that sort of representation has to be a list as far as i can understand it.
sorry just read the previous 3 posts… max is _inelegant_ at the best of times, a nasty piece of work at the worst
Yes, this makes sense.
Still, I’d say that you’re abusing binary ;)
In fact, you’re saying that each switch has three states (on, off, undefined), so why not use a ternary representation rather than binary? This would allow you to express the "undefined" state also for the significant figures of your number (in your example above, what if it was switch 1 being undefined?)
Hm, just figured I could actually always use a leading 1.
----------begin_max5_patcher---------- 591.3oc0VFsaaBCEF9Z3ovBocWVDl.Igc01KvdA1ppbfyRcEwFYaRyZUe2m8 AbCokrl1ljkQBf7wGi+8m+wlGBChVH2.5HxWH+fDD7PXP.FxEHnqbPzJ1lhJ lFSKR.2IWbazn1pLvFCF99pw5JdAPn9p3kXE1j+bpO1ujBifsBvZ9lhypHem oTx65mfleOl.kNNtKrnYEWTAFTBIcAkMFaHyuqgV8GEMxdRtZaaZyXmFUyLE 2vEKuVAEl11QmkZ6HRxrL2sT7JMebL4JWSdLLzcYzGCO0JnFDkCRmIGU5P2K c1CYn+ExPiQXLAukQ+PjYEn0rkvKPCkD6+4qqhKfBYivzelqGwnmKC0aGYo4 nWhhtnLjaN5cL8RJXIrol7S6QI4q5lEZC2zX.Lhd.CV99o0fXJ4s5rF8ry8f srW0okz81W5LrT7w1pE6NFfPSuv8Szroa8SzYmL+jdG+zmFBUY+2Xln4slo1 0sd2lIEqjKWpjM0CPijnmjgxxBCntFDrEU3n4zu9rcmqL6BLci24tqySbiSu RMvJeW3eN9YFO.WypZ7eBfs8a++zSojqcCoxAy4XST5+Vh1gxrKBfhM.2M7Y ehFpbW7corV1nJ7i9tO7hP21sf8MaAyvkhd4Xsv8j1M7xRPzm08Ea7fy1GpZ r6CQRdE0jd1Tyjc5ogUS1YSMzCPMStnlon6ZtNkxI6.fS9YCNGhZl9NYS6a7 r550fR28HQgXWA8VoxUb5HrHWzVDWExtG9ZtO+IXDlxt1lwtvVipcK5MymFE 55mGC+Cz0HC7 -----------end_max5_patcher-----------
edit: undefined is in a sense of "this switch is currently not used because there are only X outputs available, so "MSB" gets discarded either way.
I’m doing some multi-out mumbo-jumbo and each poly~ instance feeds a certain combinations of outputs, come to 16, you have unnecessarily long list to process every time, and if you want to dynamically reduce the outputs your "unpack 0 0 0 0" order gets corrupted.
Now I can just convert this 1xxxxxx binary to DEC and have a nice single value for it. :P
Maybe I should start coding; i don’t like workarounds… But I’m a lazy man…
I have come over this a few other times and it just annoyed me that a set of switches has to be in a list message because it makes so much sense for it to be a single message (to me), so this is just one of the instances I want to use it as such.
I can’t believe it never occurred to me to just use a leading 1…
… but is it "elegant" code to specifically format a message to tell a recipient "do nothing"?
I don’t know if your interested in external objects or not, Peter Elsea’s Lobjects contain an object [bit] that breaks in int into separate bits or [Lbits] that list the bits in an int including the leading zeros. ftp://arts.ucsc.edu/pub/ems/Lobjects/
("this makes sense" referred to the need to have all the data for each switch packed into a single atom, not to the inelegance of Max… I disagree with you, at least as long as you treat Max for what it is: a great tool for combining processes and user interface widgets, where complex processes are often best expressed in traditional programming languages but also possible with plain Max…)
@Wetterberg: … but is it "elegant" code to specifically format a message to tell a recipient "do nothing"?
That’s exactly what I’m try to avoiding. By sensing a message this way I can have a fixed size Pack/Unpack for larger lists while this particular part of the list can vary in size, avoiding the need to have empty "maximum message length" slots present all times.
@Nicolas Danet: Hah. Yeah. That as well. Elegant solution. I prefer the leading 1, looks more like I know what I’m doing.
@Rick: great link, but I rather keep it as vanilla as/if possible.
@Andrea Agostini: not sure that I implied anywhere that I thought you agreed on the inelegance of Max?
I really like Max, it just pisses me off sometimes. Less then most of other environment I work in anyway. :-)