23 lines
373 B
Markdown
23 lines
373 B
Markdown
---
|
|
title: Number to hex
|
|
type: snippet
|
|
language: python
|
|
tags: [math]
|
|
cover: beach-overview
|
|
dateModified: 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
|
|
```
|