Reputation: 61
Searched about this and didn't find useful help. Maybe I searched wrong. Figured I might just ask here and find out more by that.
Let's say I have 99 numbers with a range from 1 - 6 made from rolling a 6 sided dice 99 times. And I want to convert this from base6 (is this already base6 format?) to base10 in python 2.7, how would I do it? Code should be non cryptic and readable. Automatic replacement of 6's to 0's would be good to, if needed. It's for Bitcoin Private Key generation by the way. The dice rolls are being entered in manually right when it asks "Enter dice rolls: "
Basicly converting 6 sided dice rolls from number range 1 - 6 -> 0 - 5 -> 0 - 9
Don't laugh, basicly what I have written now is just this:
import ...????
dice_input = input("Enter dice rolls: ")
dice_convert_base6_to_base10 = base10.encode(dice_input)...????
No idea if or what I would need to import and what to do with the dice_input. My question may sound a bit stupid to most of you, please don't judge.. Thanks a lot for every help I can get!
Upvotes: 1
Views: 141
Reputation: 10075
Use the built-in int
function doc.
It does conversion from string
to integer
types. So, you will need to get the input as a string doc.
It accepts a second (optional) parameter of the base you want to assume the source comes from.
Code would end up looking something like:
dice_input = raw_input("Enter dice rolls: ")
dice_convert_base6_to_base10 = int(dice_input, 6)
To convert any 6
to 0
, then you could just use the replace
method of the string doc.
Code would then be changed to something like:
dice_input = raw_input("Enter dice rolls: ").replace('6','0')
dice_convert_base6_to_base10 = int(dice_input, 6)
Not certain about if this is really the way to get the key generation you want... but, I don't think I really grokked the use-case.
Upvotes: 3