Sep-26-2017, 07:03 AM
(Sep-26-2017, 06:58 AM)hbknjr Wrote: The pythonsomething like that was what i had in mind.int()
function takes in a base parameter which converts to object/string to base 10 from the given base.
Soint('101',2)
= 5.
Here's one way you can write you program
def convertToInt(num_string): determine_base ={'0x':16,'0b':2,'0o':8} # dict to detrmine base # returns base from dict defaults to None(for base 10) base = determine_base.get(num_string[:2].lower(),None) if base != None: return int(num_string[2:],base) else: return int(num_string) # prefix '0x' & '0X' => hexadecimal, '0b' & '0B' => binary, '0O' and '0o' => Octal strings = ['0xd4','0B10001','0o763','56'] for num in strings: print(convertToInt(num))
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.