I am doing a homework project about cryptography in Python. I need to convert a string representation of binary to a real binary. I mean;
binary = "00000011" should be converted to real 8bits , since I will use it for a XOR operation. How can I convert it in this way in Python?. Thank you in advance.
Asked
Active
Viewed 106 times
0
ccca
- 75
- 2
- 11
1 Answers
2
You can use the int() function to make it an integer, which takes a radix parameter:
>>> int("00000011", 2)
3
Once you have an integer, you can use the ^ xor operator:
>>> 3 ^ 1
2
Wander Nauta
- 18,832
- 1
- 45
- 62