Integer Representation — Digital Logic

🔢 Basics of Digital Logic (Integer Representation)

When we talk about numbers, we usually think of them as whole numbers — like 5, 12, or –8.
In computers, these are called integers. But here’s the twist — computers don’t see numbers the way we do. They only understand binary digits, 0s and 1s.

So, integer representation is all about how computers store and understand these whole numbers using only those two symbols.


💡 What Does “Integer Representation” Mean?

Imagine you’re teaching a robot how to count.
You say “five,” and it looks at you blankly because it only understands ON (1) and OFF (0).
So, to make it understand, you have to show it five as a pattern of bits — like 0101 in binary.

That’s what integer representation does — it gives computers a way to translate human numbers into binary form so they can work with them easily.


🧮 Two Types of Integers

Computers deal with two kinds of integers:

  1. Unsigned integers – only positive numbers and zero.
  2. Signed integers – both positive and negative numbers.

Let’s look at each one in a simple way.


⚙️ 1. Unsigned Integer Representation

Unsigned integers are the easiest.
They only represent non-negative values (0 and above).
Every bit contributes to the number’s value.

For example, if you have 4 bits:

0000 = 0  
0001 = 1  
0010 = 2  
...  
1111 = 15

So, with 4 bits, the range is 0 to 15 (that’s 2⁴ – 1).
If you add 1 to 1111 (which is 15), it wraps around to 0000 — like a counter going back to zero.


⚙️ 2. Signed Integer Representation

Now comes the more interesting part — what if we want to represent negative numbers too?

We already know that computers don’t understand a “minus” sign.
So, we use special methods to encode negative values inside those same binary bits.

There are three main ways to do this:

  • Sign-Magnitude Representation
  • 1’s Complement Representation
  • 2’s Complement Representation

Let’s keep it simple:

  • Sign-Magnitude: The leftmost bit shows the sign — 0 for positive, 1 for negative.
    Example (4 bits):
    +5 → 0101
    –5 → 1101
  • 1’s Complement: Flip every bit of the positive number to get its negative version.
    +5 → 0101 → flip → 1010 (–5)
  • 2’s Complement: Flip the bits and then add 1.
    +5 → 0101 → flip → 1010 → add 1 → 1011 (–5)

Among these, 2’s complement is the most commonly used because it makes arithmetic simple and gets rid of confusing issues like “two zeros.”


🧠 Why Represent Integers in Binary?

Binary representation is powerful because:

  • It’s simple — only two states (0 and 1).
  • It’s reliable — easy for electronic circuits to detect ON/OFF signals.
  • It’s universal — all types of data (numbers, letters, colors) can eventually be expressed using binary patterns.

So, representing integers in binary allows computers to perform math, store data, and run programs efficiently.


🧩 Example to Visualize It

Let’s imagine a 3-bit system.

For unsigned integers:

000 = 0  
001 = 1  
010 = 2  
011 = 3  
100 = 4  
101 = 5  
110 = 6  
111 = 7

For signed integers (2’s complement):

000 = 0  
001 = 1  
010 = 2  
011 = 3  
100 = -4  
101 = -3  
110 = -2  
111 = -1

Notice how the same binary patterns can mean different things depending on how we interpret them — unsigned or signed.
It’s like the same set of letters forming two different words in two languages!


Real-Life Connection

Whenever your calculator shows a negative answer, or your phone battery goes from 100% down to –1% (rare, but possible in testing!), it’s using these integer representations behind the scenes to handle both positive and negative values.

  • Integer representation is how computers store whole numbers using binary digits.
  • Unsigned integers represent only positive values.
  • Signed integers can be positive or negative, usually represented using 2’s complement.
  • This concept allows computers to perform arithmetic accurately and efficiently.