[PD] ternary counting

Mathieu Bouchard matju at artengine.ca
Thu Sep 8 17:19:40 CEST 2011


On Thu, 8 Sep 2011, Andy Farnell wrote:

> Try a [div] [mod] chain
>
> Four digits base 3 would be

Also, to have the counting itself in base 3, chain counters that count 
0,1,2,0,1,2,0,1,2,... in which each counter adds a 1 to the counter on the 
left whenever it goes from 2 to 0.

This makes a sequence like 00 01 02 10 11 12 20 21 22 as Tim wants.

This can be converted back to another number format using the opposite of 
what Andy showed :

take D3
multiply by 3
add D2
multiply by 3
add D1
multiply by 3
add D0

But the output of this, and the input of Andy's, is not necessarily in 
base 10. It is actually in the base that [mod], [div], [*] and [+] are in, 
and in the case of Pd, that's in binary.

libc's printf() function does something very much like what Andy said, to 
convert its binary ints to decimal ascii. The differences are that it says 
10 instead of 3, and it adds 48 to each digit because codes 48 through 57 
represent the 10 digits.

  _______________________________________________________________________
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC


More information about the Pd-list mailing list