Bitwise Operations

Devyn Collier Johnson devyncjohnson at gmail.com
Mon Jul 29 19:48:34 EDT 2013


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 <devyncjohnson at gmail.com> 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 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.
>
> x = (int('101', 2) & int('010', 2))
>
> Notice the quotes.
>
> In the future you'll better answers quicker if you tell us what you 
> did (such as your example above) as well as the errors.
>
> -- 
> ~Ethan~
Thanks Ethan for the code help and the tip. I need to get out of that 
habit of not including errors. This code works well, thanks! I cannot 
believe I was that close to the solution!

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?


Mahalo,

DCJ



More information about the Python-list mailing list