Skip to content

Change numeric base using Python

Hello,

How to change the numeric base of a number? This is a implementation in Python.

[code lang=”python”]
def convert(decimal,newBase,str,letters):
if decimal >= newBase:
x = decimal % newBase
y = decimal / newBase
str = letters[x] + str
if y < newBase: str = letters[y] + str return convert(y,newBase,str,letters) else: if len(str) == 0: str = letters[decimal] + str return str let = "0123456789ABCDEF" print convert(17,16,"",let) [/code] The variable let means what values used in the base. For an example if you want binary you should replace with 01. Matheus

Published inAprendendopython

399 Comments

  1. gambling match fixing tennis – Alexandria
    in canada statistics, legit casino sites canada and best online casino payout uk, or
    all australian casino no deposit bonus codes

  2. new zealandn online casino minimum deposit $10, no wagering bonus casino united states and casino frenzy 250 free spins, or $1 deposit bonus
    casino new zealand

    Feel free to visit my webpage: blackjack simulator card counting (Hiram)

  3. big pokie wins australia 2021, casimba casino nz login and casino how much money can you make in blackjack (Bernd) connecticut usa, or new poker sites uk 2021

  4. This is very attention-grabbing, You are an overly professional blogger.
    I’ve joined your feed and sit up for searching for more of your wonderful post.
    Additionally, I’ve shared your site in my social networks

    Here is my webpage … winning big at craps (Raymond)

Leave a Reply

Your email address will not be published. Required fields are marked *