Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python convert base

# 10 numbers + 26 upper case letters + 26 lower case letters + 128 printable ASCII characters = 190
alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´≡±‗¾¶§÷¸°¨·¹³²■'
print('alphabet =', len(alphabet))

Number = '12020202002020202202020200101010110101010040404044040404004040404'


def base_encoder(number, base):
    if base > len(alphabet):
        print('base not supported')

    is_negative = number < 0
    number = abs(number)
    base_number = ''

    while number:
        number, i = divmod(number, base)
        base_number = alphabet[i] + base_number
    if is_negative:
        base_number = '-' + base_number

    return base_number


def base_decoder(number, base):
    if base > len(alphabet):
        print('base not supported')
    dict_of_alph = {d: i for i, d in enumerate(alphabet)}

    base_number = sum(dict_of_alph[h] * base ** pos for pos, h in enumerate(reversed(number)))

    return base_number


def base_changer(number, in_bace, out_bace):
    print(number, 'this is bace', in_bace)
    step_0 = base_decoder(number, in_bace)
    print(step_0, 'this is base 10')
    step_1 = base_encoder(step_0, out_bace)
    print(step_1, 'this is bace', out_bace)
    return step_1


step_2 = base_changer(Number, 5, 150)
step_3 = base_changer(step_2, 150, 5)
Comment

PREVIOUS NEXT
Code Example
Python :: flask admin forgeign keys show literal 
Python :: get window coordinates selenium 
Python :: text image thresholding 
Python :: load data batchwise keras 
Python :: user_info = user_info.save(commit=False) 
Python :: Python run module with and without "-m" option and import path setting 
Python :: to find keywords in a text spacy 
Python :: apply diff subset pandas 
Python :: Filter Top 5 Python 
Python :: HTTP Error 403: Forbidden django account signup email 
Python :: How to derive using sympy 
Python :: python nltk detecting clauses in sentences 
Python :: remove the secound to last veriable in a list python 
Python :: find index corresponding to maximum value pandas 
Python :: List Creating List 
Python :: 3x3 gaussian kernel 
Python :: all classification algorithim compare 
Python :: accuracy sensitivity specificity 
Python :: networkx draw edge description 
Python :: df select custom index 
Python :: grep alternative in python 
Python :: rendere eseguibile python 
Python :: wget download file python magic 
Python :: drop values in column with single frequency 
Python :: pandas : stratification (mean) 
Python :: seconds since epoc python 
Python :: playlist discordpy 
Python :: write in file python 
Python :: how to subtract two timestamps in python with presence of + and minus in timestamps 
Python :: python hasattr function 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =