This is either basic or impossible

Jan 18, 2008 at 7:44pm

This is either basic or impossible

I know this might be simple but I need to know how to split a 12 digit number into 12 seperate integers. I’m going to use a upc scanner to generate a 12 digit number. I need to pipe each digit through my program to create an algorithmic poem. I hope that this is possible.

#35439
Jan 18, 2008 at 8:03pm

there’s probably a smarter way to do this, but this task is easy with
a bit of math…. take that 12 digits, divide by 10000000000, cut of
the decimals, and blam, there’s the 12th digit, which I’ll call X.
then take the 12 digit number, subtract (100,000,000,000 * X), then
divide by 10,000,000,000, etc, etc…

On Jan 18, 2008 2:44 PM, Joshua Jarvis wrote:
>
> I know this might be simple but I need to know how to split a 12 digit number into 12 seperate integers. I’m going to use a upc scanner to generate a 12 digit number. I need to pipe each digit through my program to create an algorithmic poem. I hope that this is possible.
>

http://www.virb.com/anthonysaunders

#120813
Jan 18, 2008 at 8:18pm

To do it in Max you would need [spell] and [itoa]

you can also do this pretty easily with java script…

function SplitString(str)
{

for(i = 0; i < 12; i++)
outlet(0, str.charAt(i));

}

—- Joshua Jarvis wrote:
>
> I know this might be simple but I need to know how to split a 12 digit number into 12 seperate integers. I’m going to use a upc scanner to generate a 12 digit number. I need to pipe each digit through my program to create an algorithmic poem. I hope that this is possible.

#120814
Jan 18, 2008 at 9:23pm

On 18 Jan 2008, at 19:44, Joshua Jarvis wrote:

> I know this might be simple but I need to know how to split a 12
> digit number into 12 seperate integers.

I’m sure you’ll get plenty of answers, but here’s a word of warning:
Max will strip any leading zeroes from your number (at least, if you
present it to Max in the lexical form of an integer). I ran into this
issue using RFID tags (which are strings of digits, not integer
values), so I ended up prefixing the digit strings with a symbol (“_”
in fact).

The downsize of *this*, of course, is that it will pollute Max’s
symbol hashtable. But the alternatives (such as presenting lists of
digits from the device) might be too complicated to contemplate.

If leading zeroes are not significant to you, then this issue is moot.

– N.

Nick Rothwell / Cassiel.com Limited
http://www.cassiel.com
http://www.myspace.com/cassieldotcom
http://www.last.fm/music/cassiel
http://www.reverbnation.com/cassiel
http://www.linkedin.com/in/cassiel
http://www.loadbang.net

#120815
Jan 18, 2008 at 9:30pm

At 12:44 PM -0700 1/18/08, Joshua Jarvis wrote:
>I know this might be simple but I need to know how to split a 12 digit number into 12 seperate integers. I’m going to use a upc scanner to generate a 12 digit number. I need to pipe each digit through my program to create an algorithmic poem. I hope that this is possible.

I think that you will run into number representation issues with a number that large. 2147483647 is as big as you can represent in 32 bits, higher than that and a 32 bit representation will wrap negative.

Does the scanner really bake a 12 digit number, or is there some way it can chunk it up into smaller pieces.

-C


Chris Muir | “There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,
http://www.xfade.com | and radicals always argue.” – Brian Eno

#120816
Jan 18, 2008 at 9:39pm

Joshua Jarvis schrieb:
> I know this might be simple but I need to know how to split a 12
> digit number into 12 seperate integers. I’m going to use a upc
> scanner to generate a 12 digit number. I need to pipe each digit
> through my program to create an algorithmic poem. I hope that this
> is possible.

The main problem will be to deal with that as a number, as 12 digits
exeed the 32-bit integer space in Max. But if you do it as a string,
there is no problem, atoi, and some filtering will give what you need…

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 92 215 30 196617 – 48;
#P number 338 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 314 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 290 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 266 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 242 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 218 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 194 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 170 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 146 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 122 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 98 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 74 286 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 74 262 274 196617 unpack 1 2 3 4 5 6 7 8 9 10 11 12;
#P newex 74 127 28 196617 t b l;
#P newex 74 241 49 196617 zl group;
#P newex 92 194 62 196617 split 48 57;
#P newex 92 172 30 196617 iter;
#P newex 92 150 30 196617 atoi;
#P message 74 100 93 196617 “123456789012″;
#P message 173 100 93 196617 “547382985732″;
#P connect 2 0 3 0;
#P connect 6 1 2 0;
#P connect 5 0 7 0;
#P connect 6 0 5 0;
#P connect 20 0 5 0;
#P fasten 0 0 6 0 178 121 79 121;
#P connect 4 0 20 0;
#P connect 7 11 19 0;
#P connect 7 10 18 0;
#P connect 7 9 17 0;
#P connect 7 8 16 0;
#P connect 7 7 15 0;
#P connect 7 6 14 0;
#P connect 7 5 13 0;
#P connect 7 4 12 0;
#P connect 7 3 11 0;
#P connect 7 2 10 0;
#P connect 7 1 9 0;
#P connect 7 0 8 0;
#P connect 1 0 6 0;
#P connect 3 0 4 0;
#P window clipboard copycount 21;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#120817
Jan 18, 2008 at 9:43pm

This problem is not so simple as it seems – if you try and write a twelve digit number like 999999999999 or even 100000000000 to a message box or number box you’ll get in trouble because they require more than 32 bits to represent them. Max at the moment is limited to 32 bits So you need to treat the number as a symbol, split up the symbol and then convert back to int’s at the end.

Here is a way to do what you want:

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 473 49 92 196617 “098765432123″;
#P message 379 49 92 196617 “123456789098″;
#P newex 418 173 64 196617 fromsymbol;
#P newex 312 99 38 196617 sel 34;
#P message 281 49 92 196617 “111111111111″;
#P number 411 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 392 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 373 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 354 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 335 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 316 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 297 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 278 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 259 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 240 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 221 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 202 225 18 9 0 0 32 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 418 151 40 196617 itoa;
#P newex 313 125 27 196617 t i b;
#N counter 0 1 12;
#X flags 0 0;
#P newobj 202 157 77 196617 counter 0 1 12;
#P newex 202 197 226 196617 gate 12;
#P newex 312 79 31 196617 spell;
#P comment 356 101 100 196617 filter out the ” char”;
#P connect 2 11 17 0;
#P connect 2 10 16 0;
#P connect 2 9 15 0;
#P connect 2 8 14 0;
#P connect 2 7 13 0;
#P connect 2 6 12 0;
#P connect 2 5 11 0;
#P connect 2 4 10 0;
#P connect 2 3 9 0;
#P connect 2 2 8 0;
#P connect 2 1 7 0;
#P connect 2 0 6 0;
#P fasten 22 0 1 0 478 72 317 72;
#P fasten 4 0 5 0 318 146 423 146;
#P fasten 4 1 3 0 335 149 207 149;
#P fasten 19 1 4 0 345 120 318 120;
#P connect 3 0 2 0;
#P fasten 21 0 1 0 384 72 317 72;
#P connect 20 0 2 1;
#P connect 5 0 20 0;
#P connect 1 0 19 0;
#P fasten 18 0 1 0 286 76 317 76;
#P window clipboard copycount 23;

#120818
Jan 18, 2008 at 9:53pm

Ha ha Stefan you beat me by 4 mins (i had to take a call) – Stephan’s is a better solution really, it’s a bit more economical.

#120819
Jan 18, 2008 at 10:43pm

LISP is pretty good at this stuff, especially the bignum
capabilities. To separate a string like “18162839718528375″ you
could use these functions (apologies for my bad prog-form lisp; I’m
old):

(defun explode(sym) (prog(str)
(setq str (make-string-input-stream (string sym)))
(return (collectem str))
)
)

(defun collectem(st) (prog(ch)
(cond ((null (setq ch (read-char st nil))) (return nil))
(t (return (cons (objectify ch) (collectem st))) )
)
)
)

(defun objectify(c)
(read (make-string-input-stream (string c)))
)

but (as others have noted) you’ll have difficulties getting this kind
of number to/from max-msp.

maxlispj here:

http://music.columbia.edu/~brad/maxlispj/

brad

http://music.columbia.edu/~brad

On Jan 18, 2008, at 2:44 PM, Joshua Jarvis wrote:

>
> I know this might be simple but I need to know how to split a 12
> digit number into 12 seperate integers. I’m going to use a upc
> scanner to generate a 12 digit number. I need to pipe each digit
> through my program to create an algorithmic poem. I hope that this
> is possible.

#120820
Jan 18, 2008 at 10:46pm

:)

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 428 408 31 196617 spell;
#P newex 445 452 30 196617 – 48;
#P number 412 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 388 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 364 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 340 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 316 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 292 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 268 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 244 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 220 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 196 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 172 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 148 497 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 148 473 307 196617 gate 13 1;
#N counter 1 14;
#X flags 0 0;
#P newobj 148 452 68 196617 counter 1 14;
#P newex 428 428 27 196617 t b i;
#P message 428 390 93 196617 “123456789012″;
#P connect 17 0 1 0;
#P connect 0 0 17 0;
#P connect 2 0 3 0;
#P fasten 1 0 2 0 433 448 153 448;
#P connect 3 1 5 0;
#P connect 3 2 6 0;
#P connect 3 3 7 0;
#P connect 3 4 8 0;
#P connect 3 5 9 0;
#P connect 3 6 10 0;
#P connect 3 7 11 0;
#P connect 3 8 12 0;
#P connect 3 9 13 0;
#P connect 3 10 14 0;
#P connect 3 11 15 0;
#P connect 16 0 3 1;
#P connect 3 0 4 0;
#P connect 1 1 16 0;
#P window clipboard copycount 18;

#120821
Jan 19, 2008 at 3:21am

that’s neat Mattijs.

#120822
Jan 19, 2008 at 3:28am

ok one last shot as i was feeling inadiquate after my first attempt – now only 3 objects….

;-p

#P window setfont “Sans Serif” 9.;
#P number 551 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 263 377 30 196617 – 48;
#P newex 263 397 327 196617 cycle 14;
#P newex 263 356 31 196617 spell;
#P number 527 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 503 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 479 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 455 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 431 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 407 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 383 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 359 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 335 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 311 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 287 423 22 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 263 336 92 196617 “123456789098″;
#P connect 12 0 14 0;
#P connect 0 0 12 0;
#P connect 13 12 15 0;
#P connect 14 0 13 0;
#P connect 13 1 1 0;
#P connect 13 2 2 0;
#P connect 13 3 3 0;
#P connect 13 4 4 0;
#P connect 13 5 5 0;
#P connect 13 6 6 0;
#P connect 13 7 7 0;
#P connect 13 8 8 0;
#P connect 13 9 9 0;
#P connect 13 10 10 0;
#P connect 13 11 11 0;
#P window clipboard copycount 16;

#120823
Jan 19, 2008 at 10:01am

Quote: Leafcutter John wrote on Sat, 19 January 2008 04:28
—————————————————-
> ok one last shot as i was feeling inadiquate after my first attempt – now only 3 objects….
>
> ;-p
>

Wow! Nice one!

Why is this so much fun?

Mattijs

#120824
Jan 19, 2008 at 6:03pm

At 11:01 AM +0100 1/19/08, Mattijs Kneppers wrote:
>Why is this so much fun?

This sort of thing _is_ fun.

But none of the solutions so far have really addressed the problem of how the original poster can get his 12 digit number into Max as text in the first place. I would like to hear from the original poster again, to better understand how the scanner delivers the numbers.

-C


Chris Muir | “There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,
http://www.xfade.com | and radicals always argue.” – Brian Eno

#120825

You must be logged in to reply to this topic.