Easy counting made complicated...

Rohman's icon

Hey folks! I'm trying to do some basic math with an external device with input and could use a little help. This is basically what I have so far:

Each of these 5 channels have an unique specific value as well as a standard "0". Basically my aim is to add all five of these channels into a singular number box for further processing. i.e. if just channel 1 is triggered, the total value is 1, and if channel 2, 3 and 4 is triggered simultaneously the total value is 14, etc etc.

So essentially the goal is to have these five channels have 32 different different values depending on what combination of channels are active. I've attempted to string together some + objects, whilst it did work in retrospect it faulted majorly when the values descended.

Any thoughts or suggestions?

1373.max_help.jpg
jpg
Luke Hall's icon

I've written a javascript that converts numbers to and from different bases, in your case decimal to binary and back again. You can find it as part of a collection of possibly useful bits here although it is written for max 5 the javascripts should work in max 4 just fine.

Luke Hall's icon

Here are two painful looking [jstrigger] snippets which should do what you need without having to worry about loading external javascript files. The first takes a decimal number and outputs the binary representation as a list of ones and zeros with no need for [fromsymbol]. The second does the reverse. Paste them into an object box and you should be ready to go!

jstrigger (a[0].toString(2).split('').map(function(x){return parseInt(x)}))

jstrigger (parseInt(parseInt(a.join().replace(',','','g'),2).toString(10)))

Rohman's icon

Hey Raja! Just implemented that chain in and it works perfectly! Thank you so much mate, you are a legend! Hell give me your e-mail sometime and I'll send you the completed project when I'm done!

Roman Thilenius's icon

here´s the 110 version for decimal to binary. should be no problem to expand it to up to 24 digits.

@luke: i dont get your download link working, might be a temp problem of the hoster.

1385.110.decim2bin-oct.zip
zip
seejayjames's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I added a couple more techniques, two are faster and one is in the middle:

Wonder where the culprit objects are? Is there any way to tell how quickly a given input to an object comes out the outlet? I mean, probably it's way too fast to measure with scheduler objects, but maybe there could be a "clocker" function that would print out the processing time, in microseconds when needed, to the Max window... would sure like to run some tests on various objects. anyway...

Jesse's icon

Simplest and fastest are the Byte object in Lobjects, and jasch's bitlist object.

Max Patch
Copy patch and select New From Clipboard in Max.

Each object has its own way of designating position of the most significant/least significant bit - hence the differing results. Same is true in your example @seejayjames.