Forums > MaxMSP

### Isolating de digits of a long number

Jun 07 2008 | 2:34 am

Hello! I get numbers of four digits in number boxes and i want to isolate
each of the four digits from the others. Do you have an idea which object
can be usefull to perform this action?

Jun 07 2008 | 3:10 am

Here’s one way:

max v2;
#N vpatcher 618 44 772 261;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 35 160 32 196617 print;
#P newex 35 135 64 196617 fromsymbol;
#P newex 35 110 40 196617 itoa;
#P newex 35 84 25 196617 iter;
#P message 35 33 34 196617 1234;
#P newex 35 58 40 196617 atoi;
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P pop;

Jun 08 2008 | 2:28 pm

Zachary’s suggestion is the lexical approach.

Here’s a numeric approach. The feedback loop is a little scary in Max land, but will *not* stack overflow with integers. Salt to taste (particularly if you want the digits printed in left-to-right order).

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 67 126 32 196617 print;
#P newex 50 181 32 196617 sel 0;
#P newex 50 155 31 196617 / 10;
#P newex 50 71 27 196617 t i i;
#P newex 67 102 34 196617 % 10;
#P message 50 39 58 196617 12345678;
#P window linecount 2;
#P comment 47 214 100 196617 Break loop when we hit zero;
#P fasten 5 1 3 0 77 205 40 205 40 63 55 63;
#P connect 4 0 5 0;
#P connect 2 0 6 0;
#P connect 3 0 4 0;
#P connect 3 1 2 0;
#P connect 1 0 3 0;
#P window clipboard copycount 7;

Incidentally, there was another thread recently claiming the rightmost outlet from sel was inutile. Au contraire. This is an idiomatic example of using sel to break a loop by only using the right outlet. Study carefully.

Viewing 3 posts - 1 through 3 (of 3 total)

Forums > MaxMSP