How to convert an integer to a string in base b with Python

2 Answers

0 votes
import numpy as np

print(np.base_repr(255, base=16)) 
print(np.base_repr(10, base=2))  



'''
run:

FF
1010

'''

 



answered Aug 17, 2025 by avibootz
0 votes
# Binary
print(bin(10)[2:])  

# Octal
print(oct(10)[2:])  

# Hexadecimal
print(hex(255)[2:].upper()) 
 


'''
run:

1010
12
FF

'''

 



answered Aug 17, 2025 by avibootz
...