evaluate a number as a derivative of 16

Jun 27, 2013 at 3:59am

evaluate a number as a derivative of 16

Hi,

Im a bit stuck would be grateful for any ideas. Im trying to evaluate an increasing number as a value of a 16th.

e.g.
1 = 1
5 = 5
17 = 1
32 = 16
34 = 2

I tried using Pow, but that only does the opposite. Is there a way to use expr on this maybe?

Any help would be much appreciated.

Cheers

#254233
Jun 27, 2013 at 4:35am

Use modulo (%) 16. But then 32 would be 0, you could change that by using an if object.

#254238
Jun 27, 2013 at 4:40am

Brilliant thankn u so much :)

#254239
Jun 27, 2013 at 9:25am

The C programmer in me can’t help noticing that, instead of using an [if], you can do [int]->[- 1]->[% 16]->[+ 1] (assuming you only use positive integers, i.e., neither zero nor any negatives… the modulo operator is a bit idiosyncratic with negative input, but that’s a different story).

In a compiled language the addition and subtraction are generally cheaper than a conditional. In Max, it probably doesn’t make any difference.

#254277
Jun 27, 2013 at 2:49pm

Peter, [int]-> [- 1]-> [%16]-> [+ 1] limits all output to 16 or less, with multiples of 16 resulting in 16. Or maybe I misunderstood you.

#254320
Jun 27, 2013 at 3:00pm

I’m also not sure the OP was entirely clear regarding the number 16.. If 5=5, 17=1 and 32=2, then what about 16? Does 16=1, 0 or 16? If 1, then 16=17. If 0, then there is an inconsistency with 32=2. So in terms of simplicity, his criteria kinda forces the hand of if.

#254321
Jun 27, 2013 at 10:37pm

I assumed, that the OP wanted 16=16 and then start from 17=1 again. So basically: n%16 but if n%16==0: output = 16. Of course then you would have to take care of n==0 with another if statement.

#254341

You must be logged in to reply to this topic.