Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27473
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bsk16@case.edu> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.03; 'binary': 0.05; 'default.': 0.07; 'work!': 0.07; 'subject:How': 0.09; 'stored': 0.10; 'aug': 0.13; '12:50': 0.16; 'integer.': 0.16; 'mon,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; 'specify': 0.17; '>>>': 0.18; 'python?': 0.20; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'first.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'argue': 0.29; 'base,': 0.29; "i'm": 0.29; 'goes': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; '20,': 0.65 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=eEpQWc5dkYjwffYGXDqmebQ0lzeG7z+0i+kEvGCEfs0=; b=Mi5EvcSShzfM6NvU8TT8IWExxajrxv+UaOVaUqI2NtgXGYQXtrAiaNeExKvvQnKQPZ TXn19M1ntrb4Q33gs63MaV5nYp2UdL0CDVVuleWwV6bEbAyZ2Kd9c2xeYx/e/v3yP+xi zzCaTcqSgunG1b5/HcKAvTyfCY74CvIr7E1Ypbr2t+68dxX/IqJJ+vS368Xxb0H9Ej0Q qxU3haE3U+VJbpqWraF+l1aISnse4YGZ4/bfDk6OtydpXoz8pAPCv+GgBF1eS/pwuGrC Fn55Hp7boX90v5Fa66Fv3TcQ/Pb0qmZb65xAfv0zA6OHGzBbsFkQ4VQDSfMrW/TPTANK EH3Q== |
| MIME-Version | 1.0 |
| In-Reply-To | <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> |
| References | <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> |
| Date | Mon, 20 Aug 2012 01:04:22 -0700 |
| Subject | Re: How to convert base 10 to base 2? |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| X-Gm-Message-State | ALoCoQkX5ie1R7a8ou996qjccSaIObrL/GSiVFrbHE8tq1rc8MBcbzxI4dWotaP0U5yNvBWvQPrM |
| X-Junkmail-Whitelist | YES (by domain whitelist at mpv2.tis.cwru.edu) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3544.1345449933.4697.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1345449933 news.xs4all.nl 6942 [2001:888:2000:d::a6]:60342 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:27473 |
Show key headers only | View raw
On Mon, Aug 20, 2012 at 12:50 AM, <gianpycea@gmail.com> wrote:
> Hi,
> as you can argue from the subject, i'm really,really new to python.
> What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work!
That syntax goes the other way- from a string representing a number in
the given base into an integer (which doesn't have a base, although
it's stored in base 2).
You get the binary by doing bin(x), where x is an integer.
>>> bin(12)
'0b1100'
If you want to go from a string in base-10 to a string in base-2, you
have to do the conversion to integer first.
>>> bin(int('5',10))
'0b101'
Although you don't need to specify the 10 because that's the default.
>>> bin(int('5'))
'0b101'
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to convert base 10 to base 2? gianpycea@gmail.com - 2012-08-20 00:50 -0700
Re: How to convert base 10 to base 2? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-08-20 01:04 -0700
Re: How to convert base 10 to base 2? Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-21 09:23 -0700
Re: How to convert base 10 to base 2? Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-21 09:23 -0700
Re: How to convert base 10 to base 2? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-20 09:10 +0100
Re: How to convert base 10 to base 2? lipska the kat <lipskathekat@yahoo.co.uk> - 2012-08-20 09:26 +0100
Re: How to convert base 10 to base 2? gianpycea@gmail.com - 2012-08-20 01:57 -0700
Re: How to convert base 10 to base 2? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-08-20 16:52 +0200
Re: How to convert base 10 to base 2? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-20 13:29 -0400
Re: How to convert base 10 to base 2? Joel Goldstick <joel.goldstick@gmail.com> - 2012-08-20 13:57 -0400
Re: How to convert base 10 to base 2? Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-20 12:00 -0600
Re: How to convert base 10 to base 2? Paul Rubin <no.email@nospam.invalid> - 2012-08-20 21:05 -0700
Re: How to convert base 10 to base 2? Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-20 12:10 -0600
csiph-web