nweatherburn
nweatherburn

Reputation: 193

Converting a binary string to a binary number as to perform binary arithmetic

In Python 2.7 I am trying to a covert a String, eg '1001' to the binary number '1001' so that I can perform binary arithmetic on it.

Specifically I want to add bin(1) and left shift the binary string.

Is there an easy way to do this (preferably in the python library)?

Upvotes: 0

Views: 311

Answers (1)

Blender
Blender

Reputation: 298206

int takes a base parameter:

>>> int('1001', 2)
9

Upvotes: 2

Related Questions