evaluate a number as a derivative of 16


    Jun 27 2013 | 10:59 am
    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

    • Jun 27 2013 | 11:35 am
      Use modulo (%) 16. But then 32 would be 0, you could change that by using an if object.
    • Jun 27 2013 | 11:40 am
      Brilliant thankn u so much :)
    • Jun 27 2013 | 4:25 pm
      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.
    • Jun 27 2013 | 9:49 pm
      Peter, [int]-> [- 1]-> [%16]-> [+ 1] limits all output to 16 or less, with multiples of 16 resulting in 16. Or maybe I misunderstood you.
    • Jun 27 2013 | 10:00 pm
      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.
    • Jun 28 2013 | 5:37 am
      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.