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,792 Comments

  1. best usa online sweepstakes casino real money (Kenneth) casino real money, online united statesn roulette simulator and roulette australia rules, or does
    the usa have casinos

  2. slot machines ontario united states, best bingo 1-90 (Beatris) sites usa 2021 and legal age for gambling
    in united states, or parhaat casino tarjousaset

  3. In the United Kingdom, True Fortune casino stands out as a trusted online gambling destination.

    Big-money jackpots and trending games are easy to find on the homepage.

    New players in the United Kingdom can claim a generous welcome bonus with free spins on their first deposit.

    Adding funds takes just a moment and play begins straight away.

    A valid licence and secure infrastructure make True Fortune a safe place to play.

    New users can check the FAQ for quick guidance on bonuses and payments.

    true fortune casino ndb true fortune casino ndb

Leave a Reply

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