July 31, 2026

Pi in the sky, drama on the ground

Printing floating point numbers in binary

Python fans learn a sneaky number trick, and the comments instantly turn into a language showdown

TLDR: A programmer showed a clever workaround for exposing a decimal number’s hidden binary form in Python by first turning it into hex and then converting piece by piece. The comments immediately made it a language bragging contest, with JavaScript users flexing that their tool can do it in one line.

A tiny math trick turned into surprisingly juicy comment-section theater after one programmer showed how to reveal a decimal number’s hidden bit-by-bit form using Python’s built-in hex display. In plain English: instead of asking Python directly for a float’s binary form and getting nowhere, the author takes a detour through hexadecimal — a compact number format computers love — then converts each digit into binary. That’s how they unpack famous numbers like pi into long strings of 1s and 0s. Nerdy? Yes. But also the exact kind of puzzle that makes coding communities light up.

And light up they did. The standout reaction came from the instantly recognizable "JavaScript can already do this" energy, with one commenter breezily dropping Math.PI.toString(2) like they were slamming a reverse card onto the table. That kicked off the classic programming-language subtext: is Python missing something obvious, or is this just a neat workaround that proves coders can build whatever they want anyway? The mood wasn’t angry so much as smug-meets-playful, with a side of “why make this hard?”

The funniest part is how quickly the crowd moved from “cool number trick” to “actually my language does it cleaner.” It’s the oldest internet ritual: one person shares a clever hack, and the replies become a mini talent show for rival tools. The result is half math lesson, half fandom skirmish — and somehow, that makes this little floating-point post way more entertaining than it has any right to be.

Key Points

  • The article states that hexadecimal floating-point numbers can be converted to binary by converting each hex digit into its 4-bit binary equivalent.
  • Python is described as lacking a direct function to print a float in binary form, but Python floats provide a `.hex()` method.
  • The hexadecimal representation of `math.pi` is shown as `0x1.921fb54442d18p+1`, where `p+1` denotes a base-2 exponent.
  • To obtain the binary value, the significand is converted digit by digit from hex to binary and the binary point is shifted according to the exponent.
  • For the example `1.03`, the article shows that `bin()` can help convert the fractional hexadecimal digits, with zero-padding added when needed to preserve full 4-bit groups.

Hottest takes

"Math.PI.toString(2)" — sheept
"you'd just take 1 followed by the bits of the mantissa" — sheept
"printing the binary representation of floating point numbers is relatively easy" — sheept
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.