This is either basic or impossible

Sub Avian Flow's icon

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.

anthonysaunders's icon

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.
>

Anthony Palomba's icon

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.

nick rothwell | project cassiel's icon

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
www.cassiel.com
www.myspace.com/cassieldotcom
www.last.fm/music/cassiel
www.reverbnation.com/cassiel
www.linkedin.com/in/cassiel
www.loadbang.net

Chris Muir's icon

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

Stefan Tiedje's icon

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...

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

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

Leafcutter John's icon

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:

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

Leafcutter John's icon

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.

Brad Garton's icon

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:

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.

Mattijs's icon

:)

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


Leafcutter John's icon

that's neat Mattijs.

Leafcutter John's icon

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

;-p

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

Mattijs's icon

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

Chris Muir's icon

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