Files
30-seconds-of-code/snippets/to_hex.md
2022-06-09 13:00:34 +03:00

23 lines
409 B
Markdown

---
title: Number to hex
tags: math
expertise: beginner
cover: blog_images/green-plant.jpg
firstSeen: 2020-10-09T09:45:47+03:00
lastUpdated: 2020-10-09T09:45:47+03:00
---
Returns the hexadecimal representation of the given number.
- Use `hex()` to convert a given decimal number into its hexadecimal equivalent.
```py
def to_hex(dec):
return hex(dec)
```
```py
to_hex(41) # 0x29
to_hex(332) # 0x14c
```