DEV Community

Tony Colston
Tony Colston

Posted on

3 1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay