# Failed to use Python hex() function in Mojo

**URL:** <https://forum.modular.com/t/failed-to-use-python-hex-function-in-mojo/1586>\
**Category:** Mojo\
**Created:** [June 4, 2025, 5:50pm UTC](https://forum.modular.com/t/failed-to-use-python-hex-function-in-mojo/1586 "2025-06-04T17:50:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![notooth](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@notooth](https://forum.modular.com/u/notooth)\
**Post date:** [June 4, 2025, 5:50pm UTC](https://forum.modular.com/t/failed-to-use-python-hex-function-in-mojo/1586/1 "2025-06-04T17:50:57Z")

</div>

I failed to use Python `hex()` function in Mojo. Can anyone help?  
Python:

```auto
>>> hex(1087708488090796312015500987775900609011594597057856802365942675436720650738)
'0x2679f06244ddaea6bd268fe7331924551faf32445221f51372f57270b0c79f2'

```

Mojo:

```auto
builtins = Python.import_module("builtins")
hex_str = builtins.hex(1087708488090796312015500987775900609011594597057856802365942675436720650738)
print(hex_str)

```

```auto
error: integer value 1087708488090796312015500987775900609011594597057856802365942675436720650738 requires 251 bits to store, but the destination bit width is only 64 bits wide

```

---

<div class="post-metadata">

**Author:** ![sora](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sora](https://forum.modular.com/u/sora)\
**Post date:** [June 4, 2025, 7:36pm UTC](https://forum.modular.com/t/failed-to-use-python-hex-function-in-mojo/1586/2 "2025-06-04T19:36:10Z")

</div>

The number gets automatically converted to `Int`, which is 64 bits wide on 64-bit systems.  
Unfortunately, casting to `UInt128` or a larger type also won’t work:

- We didn’t implement that path to Python.
- Blocked by this bug: [[BUG] Cant instantiate variable of UInt256 with more than 128 bit value · Issue #4049 · modular/modular · GitHub](https://github.com/modular/modular/issues/4049)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [December 1, 2025, 7:36pm UTC](https://forum.modular.com/t/failed-to-use-python-hex-function-in-mojo/1586/3 "2025-12-01T19:36:50Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
