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

  1. Yo car enthusiasts Some agencies give you scratched-up cars that don’t match the pics Almost gave up on renting high-end cars here Finally stumbled upon a legit service — miami luxury car rentals for bachelor parties Drop-off and pick-up effortless Anyway, click so you don’t lose it — porsche rental near me https://www.pinterest.com/pin/1092122978527737190 Don’t fall for those sketchy rental agencies Send this to anyone planning a Miami trip in style

  2. Люди помогите советом Брат снова сорвался Жена в истерике В больницу тащить страшно Короче, только это реально спасло — вызвать нарколога на дом быстро Приехал через 40 минут В общем, телефон и цены тут — вызов нарколога на дом воронеж https://kodirovanie.narkolog-na-dom-voronezh15.ru Нарколог на дом — это реальный выход Перешлите тем кто в такой же ситуации

  3. 777 danmachi memoria freese casino (Drusilla) united kingdom,
    888 poker withdrawal united states and largest casino in australia 2021,
    or united statesn casino free spins no deposit

  4. best casino bonus new zealand, free spins new casino usa and casino deposit bonus usa, or northern lights
    casino uk

    Feel free to surf to my blog beste no account casinos (Christie)

Leave a Reply

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