3.1.3 · HinglishBoolean Algebra & Logic Gates

Two's complement signed numbers

1,496 words7 min readRead in English

3.1.3 · Hardware › Boolean Algebra & Logic Gates


Two's complement KYA hai?

  • bits ke liye range: .
  • Example (8-bit): . Dhyan do yeh asymmetric hai — positives se ek zyada negative.

Yeh anokha "negative weight" KYU kaam karta hai?

Formally: bits ki unsigned value hai. Hum chahte hain ki jab top bit set ho toh negatives milein, aur arithmetic mod ho. Toh signed value define karo: Jab ho: — bilkul definition wala negative weight. KYU: subtract karna ek -bit machine ko invisible hai (woh bas top se drop ho jaata hai), toh hardware ko kabhi jaanna nahi padta ki hum "mean" kar rahe the ya .


Kisi number ko negate KAISE karein (find )


Worked examples

Figure — Two's complement signed numbers

Overflow — woh ek cheez jo carries nahi bata sakti


Common mistakes


Recall Feynman: ek 12-saal ke bacche ko explain karo

Ek clock imagine karo jisme 12 ki jagah 16 hours (0–15) hain. Aage jaana add karne jaisa hai; 0 se ek ghante peeche jaane par 15 aa jaata hai. Toh is clock par, "15" matlab "ek kadam peeche" = . Hum bas agree karte hain ki clock ke doosri taraf ke numbers (8–15) "negative" hain. Kisi number ka negative nikaalene ke liye, uss number ko clock par doosri direction mein chalao — aur yeh karne ki quick trick hai: saare switches flip karo (0↔1) aur ek add karo. Yahi two's complement hai!


n-bit two's complement mein MSB kaunsa weight carry karta hai?
(ek negative weight, sirf sign flag nahi)
n-bit two's complement number ki range kya hai?
8-bit two's complement number ki range kya hai?
Two's complement mein kaise compute karte hain?
Saare bits invert karo phir 1 add karo (kyunki )
Invert-and-add-1 negative kyun deta hai?
, toh
Signed addition mein carry-out ke saath kya karte hain?
Discard kar do; yeh ke barabar hai
Signed overflow kaise detect karte hain?
Carry into MSB carry out of MSB, yaani
11111011 (8-bit two's complement) decode karo.
Range asymmetric kyun hai?
Single zero code ek extra pattern negatives ke liye free karta hai, isliye positives se ek zyada negative milta hai
8-bit mein ko negate karne par kya milta hai?
Waapis (overflow — iska koi positive counterpart nahi hai)

Connections

  • Binary number system — unsigned foundation jis par yeh build karta hai
  • Sign-magnitude representation — simple alternative (two zeros, symmetric)
  • One's complement — beech ka step (sirf invert karo, +1 nahi)
  • Full adder — woh circuit jo signed add/subtract ke liye "just works"
  • Modular arithmetic — kyun "mod " carry ko vanish karta hai
  • Overflow and carry flags — ALU mein status bits

Concept Map

motivates

redefines

defines

bounds

is

justifies

1111 behaves as

rearranged gives

used in

used in

enables

No minus sign wire

Two's complement

MSB negative weight -2^n-1

V = -b*2^n-1 + rest

Range asymmetric -2^n-1 to 2^n-1 -1

Sign bit: 1 means negative

Odometer wrap-around mod 2^n

-1

x + NOT x = 2^n - 1

-x = NOT x + 1

Encode: invert then add 1

Decode: sum weights

One adder for add and subtract