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

199 Comments

  1. best online casino reviews in united states, usa casino in new delhi; Lisette, club mobile
    and canada best slot machine, or best real money pokies
    new zealand

  2. uk casino no deposit bonus no wagering, legitimate online casino in canada and best australian online casino bonuses,
    or top gambling expansion in pa (Karl) sites usa

  3. online blackjack multiplayer free no download (Amber) free
    casino united states, european roulette betting uk and how many pokies are in united states,
    or how to win at united statesn roulette

  4. united statesn roulette online fast, best online casino sites
    new zealand and free $100 casino chip 2021 usa, or casinos in alberta australia

    Also visit my homepage gamblingforums, Agustin,

  5. Spot on with this write-up, I truly feel this amazing site needs a great deal more attention. I’ll probably be returning to read through more, thanks
    for the advice!

    Also visit my website … casino voucher theft – Lewis

Leave a Reply

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