Lets say I have the binary number 0b110, which is 6, and I want to multiply the number by 3, to get 18 which is 0b10010. How would I do that in Python, I tried multiplying it normally, but it didn't work...
-
Won't typecasting binary to int and then back do the trick?skytreader– skytreader2012-02-21 17:41:25 +00:00Commented Feb 21, 2012 at 17:41
-
"I tried multiplying it normally" - not sure what you mean by that. First off, do you know how to multiply in binary (without any specific language)?Widor– Widor2012-02-21 17:41:59 +00:00Commented Feb 21, 2012 at 17:41
-
2@skytreader: binary numbers are ints, decimal numbers are ints, Xary numbers are ints, no need to cast.Niklas B.– Niklas B.2012-02-21 17:42:05 +00:00Commented Feb 21, 2012 at 17:42
-
@NiklasB. Fair point. I was thinking OP wanted results displayed in 0s and 1s representation though. Hence, the typecasting.skytreader– skytreader2012-02-21 17:44:27 +00:00Commented Feb 21, 2012 at 17:44
-
What did you try? What was your expected output? What was your actual output?Russell Borogove– Russell Borogove2012-02-21 18:17:27 +00:00Commented Feb 21, 2012 at 18:17
Add a comment
|