Skip to content

Latest commit

 

History

History
56 lines (32 loc) · 1.9 KB

File metadata and controls

56 lines (32 loc) · 1.9 KB

🔻 Less Than Zero (Signed Bit Detection)

🧠 Overview

How does a computer know the difference between 11111101 being -3 and 253? The answer lies in signed number representation — specifically, the two’s complement system used in modern CPUs.

In a two’s complement system, the most significant bit (MSB) — the leftmost bit — represents the sign of the number:

  • 0 = positive or zero

  • 1 = negative

This allows the same binary adder circuits to handle both positive and negative values without needing separate subtraction hardware.

⚙️ How It Works in NANDGame

When working with 16-bit values:

  • Bits 0 through 14 represent the magnitude

  • Bit 15 (the highest bit) is used as the sign bit

The Less Than Zero circuit checks if this sign bit is HIGH (1):

  • If so, the number is negative

  • If it’s 0, the number is positive or zero

This is how a CPU determines that a number like 1111 1111 1111 1101 is actually -3, not 65533, based solely on the sign bit.

🔁 Circuit Summary

  • A simple wire connection to bit 15 (MSB) is used.

  • This bit acts as a flag:

  • 1 → number is less than zero

  • 0 → number is greater than or equal to zero

🔢 Example (8-bit context for clarity)

Binary Value Decimal Value MSB Less Than Zero?
0000 0011 3 0 ❌ No
1111 1101 -3 1 ✅ Yes
1000 0000 -128 1 ✅ Yes
0111 1111 127 0 ❌ No

📄 What I Learned

  • Two’s complement enables subtraction and negative values using the same binary adder

  • The most significant bit (MSB) doubles as the sign bit in signed integers

  • By checking just one bit, the CPU can determine whether a number is less than zero

  • This circuit becomes a key condition for branching, comparisons, and arithmetic checks in processors