Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51529
| References | <mailman.5275.1375134621.3114.python-list@python.org> <kt6o8t$l55$1@reader1.panix.com> <51F6FBE8.8000106@Gmail.com> <51F6FDB2.9040307@stoneleaf.us> <51F6FF52.4040806@Gmail.com> |
|---|---|
| Date | 2013-07-30 01:07 +0100 |
| Subject | Re: Bitwise Operations |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5294.1375142869.3114.python-list@python.org> (permalink) |
On Tue, Jul 30, 2013 at 12:48 AM, Devyn Collier Johnson
<devyncjohnson@gmail.com> wrote:
> Now here is something that confuses me, the binary numbers are numbers not
> strings, so why are they put in quotes as if they are strings?
They aren't numbers at that point, they're strings of digits. A number
is represented in various forms:
>>> 1234, 0x4d2, 0o2322, 0b10011010010
(1234, 1234, 1234, 1234)
The two-argument form of int() takes a string of digits and a base:
>>> int("ya",36)
1234
In base 36, y and a are digits. But in Python's base syntax, you can't
use them that way, so there's no way to render the number other than
as a string.
For what you're doing, I think the 0b notation is the best. It's an
int literal written in binary.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Bitwise Operations Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-29 17:25 -0400
Re: Bitwise Operations Grant Edwards <invalid@invalid.invalid> - 2013-07-29 21:53 +0000
Re: Bitwise Operations Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-29 19:34 -0400
Re: Bitwise Operations Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-07-30 08:20 +0200
Re: Bitwise Operations Ethan Furman <ethan@stoneleaf.us> - 2013-07-29 16:41 -0700
Re: Bitwise Operations Chris Angelico <rosuav@gmail.com> - 2013-07-30 00:44 +0100
Re: Bitwise Operations Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-29 19:48 -0400
Re: Bitwise Operations Chris Angelico <rosuav@gmail.com> - 2013-07-30 01:07 +0100
Re: Bitwise Operations MRAB <python@mrabarnett.plus.com> - 2013-07-30 02:55 +0100
Re: Bitwise Operations Terry Reedy <tjreedy@udel.edu> - 2013-07-30 01:46 -0400
csiph-web