Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AnytoBase10:
- I'm a bit tired so I'll keep this brief, you guys will have to work a little harder for this one.
- Let's say your input is base 2: 1110
- In order to convert that base 2 into decimal, you do each digit * 2^(i) + the next
- that translates to: 0 *2^(0) + 1 * 2^(1) + 1 * 2(2) + 1 *2^(3)
- solve that, it equals 14.
- if say, you wanted base 4 then again, input but times 4^(i) this time.
- 2 * 4^(0) + 3 * 4(1) = 14
- The trickiest part here is getting each digit seperated so I'll leave you with this
- ///
- number = int(input("Enter your number: "))
- digit1 = number % 10
- digit2 = (number / 10) % 10
- digit3 = (number / 100) % 10
- digit4 = (number / 1000) % 10
- print(int(digit1), int(digit2), int(digit3), int(digit4))
- /// run and print, input = 2196
- terminal: 6 9 1 2
- now slap that into a for loop since you dont know how many times you'll have to go through this step.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement