Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

How are signed integers represented using two’s complement?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-sonnet-20241022’s answer.
  1. User

    How are signed integers represented using two’s complement?

  2. Claude Assistant

    Two's Complement: Representing Signed Integers

    Two's complement is the most common method computers use to represent signed integers in binary. It elegantly handles both positive and negative numbers without needing a separate sign bit.

    Core Concept

    In an n-bit two's complement system:

    • Positive numbers: Standard binary representation (most significant bit is 0)
    • Negative numbers: Complement (flip) all bits of the positive number and add 1 (most significant bit is 1)

    How to Find the Two's Complement of a Number

    To represent -X in two's complement:

    1. Write X in binary
    2. Flip all bits (0→1, 1→0)
    3. Add 1 to the result

    Key Properties

    • The most significant bit (MSB) serves as the sign bit: 0 for positive, 1 for negative
    • No wasted bit patterns (unlike sign-magnitude representation)
    • Addition and subtraction work naturally without special handling
    • The negative of a negative number is found by applying the same algorithm

    Example (8-bit)

    DecimalBinary (Two's Complement)Explanation
    +700000111Standard binary
    -711111001Flip bits of +7 (11111000) and add 1
    +12701111111Largest positive number
    -12810000000Smallest negative number
    -111111111Flip bits of +1 (00000001) and add 1
    000000000Zero (positive)

    Range for n-bit Systems

    For n bits, the range is: -2^(n-1) to 2^(n-1)-1

    • 8-bit: -128 to +127
    • 16-bit: -32,768 to +32,767
    • 32-bit: -2,147,483,648 to +2,147,483,647

    Arithmetic Observation

    In two's complement, adding a number and its negative yields all zeros (with an ignored overflow bit)—a natural consequence of the representation that makes arithmetic circuits simpler.

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