# Converting Floating Point Numbers to Binary Using Python Hex

Original title: Printing floating point numbers in binary

> Hacker News story 49084645 · language: en · submitted 2026-07-28
> Web version: https://zeli.app/story/49084645
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 8 · by [ibobev](<https://news.ycombinator.com/user?id=ibobev>) · 💬 2
[original](<https://www.johndcook.com/blog/2026/07/27/float-binary/>) · [HN discussion](<https://news.ycombinator.com/item?id=49084645>)

## Summary

I discovered that Python lacks a direct function to convert floating point numbers to binary, but the hex method offers a clever workaround. By leveraging the hex representation and its base-2 exponent, I can manually transform each hexadecimal digit into binary. This approach reveals the precise binary structure of numbers like pi and 1.03, bridging the gap between hexadecimal and binary formats for floating point values.

## Key quote

> I imagine it's less well known that you can do the same thing with floating point numbers.

---

## Cite

- Page: https://zeli.app/story/49084645
- Date: 2026-07-28
- Source: johndcook.com (https://www.johndcook.com/blog/2026/07/27/float-binary/)
- Hacker News: https://news.ycombinator.com/item?id=49084645

## Other languages

- zh: https://zeli.app/zh/story/49084645 · markdown: https://zeli.app/zh/story/49084645.md
