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

1,739 Comments

  1. how many native united statesn casinos are there, best casino in caribbean (Luisa) usa poker rooms and how many gambling casinos are in the united states, or poker sites australia 2021

  2. australian online casino bonus codes 2021, free spins no deposit online casino ace australia and real money online casinos united states, or how to win at united statesn roulette

  3. online who owns the casino in niagara falls [Brandon] games australia free, uk casino sign up and top online pokies and casinos
    canadian dollars, or age to enter casino in united kingdom

  4. casino sites uk no deposit bonus, deposit £1 casino bonus usa
    and legal age for gambling in united states, or casino in christchurch
    new zealand

    my site eye of horus gambler demo (Betty)

  5. canadian online pokies no minimum deposit, best online
    poker games united kingdom and free bonus no deposit uk slots,
    or blackjack cosh uk

    Feel free to surf to my webpage what happened to casinodaddy (Riley)

Leave a Reply

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