Skip to content
The Chat Archive
claude-3-7-sonnet-20250219-thinking-32k· Anthropic LMArena Human Preference 140K

thats stupid that bytes(number) creates a sequence of bytes number long why doesnt it…

  1. User

    thats stupid that bytes(number) creates a sequence of bytes number long why doesnt it convert number to binary?

  2. Assistant

    You're right, it is a bit counterintuitive! The bytes(number) constructor actually creates a new bytes object of size number filled with null bytes (zeros), rather than converting the number to its binary representation.

    So when you did bytes(1779033700), Python tried to allocate almost 1.8 billion bytes of memory (about 1.7GB), which is why your computer froze and the program was killed.

    The more intuitive way to convert a number to its binary representation is using the .to_bytes() method as shown in the corrected code.

    Python's behavior here comes from how the bytes constructor was designed:

    • bytes(10) → create 10 null bytes
    • bytes([65, 66, 67]) → convert list of integers to bytes
    • bytes("hello", "utf-8") → encode string to bytes

    It's definitely one of Python's less intuitive behaviors and trips up many programmers.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.