How to select individual digits from a decimal number?

Feb 25, 2011 at 2:58pm

How to select individual digits from a decimal number?

Hi, i have a problem i need to fix, i have a system giving a decimal number of 8 digits.

eg. 10010001 (with no spaces)

I need to be able to tell wether a certain digit in the number is 1 or 0, for example as above if digit 4 is at 1 then bang output, etc etc.

any help would be great as i have searched the help files and consulted my collegues, i hope i am just overlooking something simple.

thanks

matomato

#55185
Feb 25, 2011 at 3:10pm

I would also be very interested in knowing if this can be done easily, but i am working with binary numbers.

#198644
Feb 25, 2011 at 4:51pm

Last time I looked, these questions were answered in the tutorials.

With decimal use % and /.

For instance, to get the hundreds digit [num]->[/ 100]->[% 10]

To extract bits, use the [&] object to mask out the bit you’re interested in, then optionally bit shift with [>>].

For instance, to get bit 3 (counting from *right* starting with zero) [num]->[& 8]->[>> 3].

If you just want to use the calculation to control a logic object (like if or a ggate), you can skip the bit shift.

These are really not Max-specific questions, they are fundamental DP techniques.

#198645
Feb 25, 2011 at 5:00pm

Hello,

All decimal digits with [regexp] :

– Pasted Max Patch, click to expand. –

edit : oops (backreferences) ;-)

#198646
May 17, 2011 at 2:11pm

GREAT, thank you Vanille!

#198647

You must be logged in to reply to this topic.