DEV Community

Tony Colston
Tony Colston

Posted on

converting from decimals to binary in Python

I started listening to this podcast

https://www.codenewbie.org/basecs/3

Which so far seems like a good podcast to listen to if you are starting to learn about Computer Science. Or just want a refresh.

While listening to the first episode I wondered ...

In Python how do you convert into hex or binary from a decimal number?

a = 43
print(a)
# now binary
print(bin(a))
# now hex
print(hex(a))
Enter fullscreen mode Exit fullscreen mode

The functions bin and hex will convert a number into a string representation for binary and hexadecimal.

Top comments (0)