[SciPy-user] Integer to binary [Was: Fitting sphere to 3d data points]

Jan Groenewald jan@aims.ac...
Fri Mar 2 10:53:22 CST 2007


Hi Franck

When you post, please don't reply to another thread of messages with
a good descriptive subject. Your message not only gets lost by any
email client that sorts by threads (mails with the same subject matter)
it also annoys some readers who use this feature.

Please start a blank message if you have a new question, and give it
a descriptive subject.

On Fri, Mar 02, 2007 at 12:15:50PM +0200, Franck Kalala Mutombo wrote:
> I have a sequence of decimal number (1,2,...16) for example, I want if
> there is any function  which can convert each one in binary.

A quick google of int2bin+python found this:

def int2bin(num, width=32):
    return ''.join(['%c'%(ord('0')+bool((1<<k)&num)) for k in range((width-1),-1,-1)])

cheers,
Jan
-- 
   .~.
   /V\     Jan Groenewald
  /( )\    www.aims.ac.za
  ^^-^^


More information about the SciPy-user mailing list