[PD] converting decimal to binary

Chuckk Hubbard badmuthahubbard at gmail.com
Tue Jun 27 14:39:35 CEST 2006


What type of output are you looking for?  Because beyond 6 digits,
Pd's floating point numbers look funny, and 6 digits only covers 63 in
binary.  Do you want a character string?
I don't know what kind of format you can work with.  Pd could,
alternatively, output 1's and 0's sequentially as a series of floats.

On 6/25/06, adam armfield <adamairmailed at yahoo.com> wrote:
> this is making my brain hurt... is there an object to
> do it automatically?...
>
> for various reasons (mostly due to being on a windows
> machine and wanting a quick solution) i'd like to do
> this with expr or other built in objects (ruby, py
> etc. not really an option as of now)
>
> i've got a snippet of python from the net, would
> anyone translate this into an expr for me?
> (in return for my eternal gratitude ;-)
>
> def Denary2Binary(n):
>    '''convert denary integer n to binary string
> bStr'''
>    bStr = ''
>    if n < 0:  raise ValueError, "must be a positive
> integer"
>    if n == 0: return '0'
>    while n > 0:
>        bStr = str(n % 2) + bStr
>        n = n >> 1
>    return bStr
>
> all the best
>
> adam
>
>
>
>
>
> ___________________________________________________________
> All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
> http://uk.docs.yahoo.com/nowyoucan.html
>
> _______________________________________________
> PD-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>


-- 
"Far and away the best prize that life has to offer is the chance to
work hard at work worth doing."
-Theodore Roosevelt




More information about the Pd-list mailing list