Re: Bitwise Operations

2013-07-30 Thread Ulrich Eckhardt
Am 30.07.2013 01:34, schrieb Devyn Collier Johnson: Typing "101 & 010" or "x = (int(101, 2) & int(010, 2))" only gives errors. What errors? Check out Eric Raymond's essay on asking smart questions, it's a real eye-opener! ;) That said, use "0b" as prefix for binary number literals (0b1000 is

Re: Bitwise Operations

2013-07-29 Thread Terry Reedy
On 7/29/2013 7:44 PM, Chris Angelico wrote: But there's an easier way: x = 0b101 & 0b010 x 0 I think that might do what you want. Also check out the bin() function, which will turn an integer into a string of digits. >>> bin(0b101 | 0b010) '0b111' Now you are set to go. Have fun. -- Terry

Re: Bitwise Operations

2013-07-29 Thread Peter Otten
Devyn Collier Johnson wrote: > On Python3, how can I perform bitwise operations? For instance, I want > something that will 'and', 'or', and 'xor' a binary integer. >>> 0b1010 | 0b1100 14 >>> bin(_) '0b1110' >>> 0b1010 & 0b1100 8 >>> bin(_) '0b1000' >>> 0b1010 ^ 0b1100 6 >>> bin(_) '0b110' --

Re: Bitwise Operations

2013-07-29 Thread MRAB
On 30/07/2013 00:34, Devyn Collier Johnson wrote: On 07/29/2013 05:53 PM, Grant Edwards wrote: On 2013-07-29, Devyn Collier Johnson wrote: On Python3, how can I perform bitwise operations? For instance, I want something that will 'and', 'or', and 'xor' a binary integer. http://www.google.co

Re: Bitwise Operations

2013-07-29 Thread Chris Angelico
On Tue, Jul 30, 2013 at 12:48 AM, Devyn Collier Johnson 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 var

Re: Bitwise Operations

2013-07-29 Thread Devyn Collier Johnson
On 07/29/2013 07:41 PM, Ethan Furman wrote: On 07/29/2013 04:34 PM, Devyn Collier Johnson wrote: On 07/29/2013 05:53 PM, Grant Edwards wrote: On 2013-07-29, Devyn Collier Johnson wrote: On Python3, how can I perform bitwise operations? For instance, I want something that will 'and', 'or',

Re: Bitwise Operations

2013-07-29 Thread Chris Angelico
On Tue, Jul 30, 2013 at 12:34 AM, Devyn Collier Johnson wrote: > > I understand the symbols. I want to know how to perform the task in a script > or terminal. I have searched Google, but I never saw a command. Typing "101 > & 010" or "x = (int(101, 2) & int(010, 2))" only gives errors. Your probl

Re: Bitwise Operations

2013-07-29 Thread Ethan Furman
On 07/29/2013 04:34 PM, Devyn Collier Johnson wrote: On 07/29/2013 05:53 PM, Grant Edwards wrote: On 2013-07-29, Devyn Collier Johnson wrote: On Python3, how can I perform bitwise operations? For instance, I want something that will 'and', 'or', and 'xor' a binary integer. http://www.google

Re: Bitwise Operations

2013-07-29 Thread Devyn Collier Johnson
On 07/29/2013 05:53 PM, Grant Edwards wrote: On 2013-07-29, Devyn Collier Johnson wrote: On Python3, how can I perform bitwise operations? For instance, I want something that will 'and', 'or', and 'xor' a binary integer. http://www.google.com/search?q=python+bitwise+operations I understand

Re: Bitwise Operations

2013-07-29 Thread Grant Edwards
On 2013-07-29, Devyn Collier Johnson wrote: > On Python3, how can I perform bitwise operations? For instance, I want > something that will 'and', 'or', and 'xor' a binary integer. http://www.google.com/search?q=python+bitwise+operations -- Grant Edwards grant.b.edwardsYo

Re: Bitwise operations in Python?

2005-08-18 Thread John Machin
Carl wrote: > Dear friends, > > I am currently porting a fortran program to Python but am stuck on the > intrinsic IBITS function. > > Does anyone know about a replacement function for IBITS in Python? > > Yours, Carl > > IBITS(I, POS, LEN) > > Extracts a sequence of bits. > > I > must b

Re: Bitwise operations in Python?

2005-08-18 Thread Carl
Incredible, Paul! Thanks a thousand times! /Carl -- http://mail.python.org/mailman/listinfo/python-list

Re: Bitwise operations in Python?

2005-08-18 Thread Paul Rubin
Carl <[EMAIL PROTECTED]> writes: > IBITS(I, POS, LEN) > Extracts a sequence of bits. > The result has the value of the sequence of LEN bits in I beginning at bit > POS, right-adjusted and with all other bits zero. > > The bits are numbered from 0 to BIT_SIZE(I)-1, from right to left. > > Examples