[Tutor] string to binary and back... Python 3

Prasad, Ramit ramit.prasad at jpmorgan.com
Thu Jul 19 21:23:05 CEST 2012


> A question I have for the group before I respond is a option that I saw
> that I had earlier was to ord() each element of a string and then bin()
> that number. But since bin() produces a string I could not figure out
> the correct way to attach two bin() outputs back together again due to
> the leading 'b' and even if I use lstrip('b') I was not sure if that
> would be correct?

bin(integer).split('b')[1].zfill( multiple_of_eight )

> My next hesitation is can the same or at least similar techniques be
> applied to a file? I want to be able to work on both files and strings.

Probably, but it depends on what you are trying to do and what
data you are dealing with.

Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list