1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| def get_num_common(original_num, base_num): result = [] while(original_num/base_num > base_num): result.append(original_num%base_num) original_num = original_num//base_num result.append(original_num%base_num) result.append(original_num//base_num) result.reverse() new_num = ''.join(str(i) for i in result) if base_num == 2: return '0b' + new_num elif base_num == 8: return '0o' + new_num elif base_num == 16: return '0x' + new_num elif base_num == 10: return int(new_num) else: return None
|