6.LOGIC GATES

We have already introduced Java programming to you. Before proceeding
further on the journey of Java, it is very important to know
how computers do arithmetic operations. We already know that through
programming in any language we give instructions to computer to get our
task done. We also know that we provide instructions in
high-level language which is English-like language & there are
compiler software which translate those into language which computer can
understand (the binary language). Obviously, we can’t get the task done by
computer if it does not understand our request!

This is an universal truth that CPU which is the brain of the computer
operates completely in binary language. Whether it is ALU, MU or CU,
all operate in binary language. So in this chapter we will understand
how computer performs arithmetic operation in its ALU unit of CPU. To be
a good programmer, you must be aware of what is happening inside that
CPU/laptop/computer box when you will be coming & doing multiple
times arithmetic operations during programming.

Please develop a curiosity in your mind how arithmetic operations are
performed by computer.

We already read in previous chapter that CPU is a chip consisting of
millions of Integrated Circuits (ICs). ALU is also a part of CPU hence
it also consists of millions of ICs. An IC looks like this

whatsapp image 2026 05 19 at 4.16.32 pm

Logic Gate — Here we are introducing a new word called logic gate.
Logic gate is a fundamental unit of IC shown above. You can visualize
above IC as having several logic gate.

whatsapp image 2026 05 19 at 4.34.09 pm

Logic gate takes one or more i/p & produces one output. Needless to
say, the gate is made up of transistor, diodes, resistors,
capacitors etc. You would have read about these terms in your physics/
electronics subject.

ALU stands for Arithmetic & Logic Unit. So Arithmetic and Logic operations
are performed by CPU by involving multiple logic gates. There are several types of logic gates. We will
discuss logic gates after discussing the binary numbers.

I. Decimal numbers — Our heart is closest to decimal numbers. All
the decimal numbers in this world are made by combining one or
more digits in the set of {0,1,2,3,4,5,6,7,8,9}. As this set
consists of 10 digits, we say that decimal no. system has
base 10. Addition, Subtraction, Multiplication & division is
pretty simple as it is taught to you right from your
primary school so not discussing it.

II. Binary number — Our computer’s heart is closest to binary no
numbers. All the binary numbers inside all the
computers/laptops/smartphones etc. in the world are made by
combining one or more digit in the set of {0,1}. As the set
consists of 2 digits, we say that binary no. system has base 2.
We will see Addition, Subtraction, Multiplication & division but
before that we should see how computer converts decimal no.
provided by us into binary no.

Decimal no. system has base 10 means we have 10 different figures
to represent/quantify anything in the world — no. of soldiers in
army, marks you got in 10th, no. of houses in your locality etc. Write down the 10 different figures.

First figure — 0 [Human thought: this digit representing nothing]
Now next digit coming will be the result of adding 1 to the digit.
The second figure — 1 [is obtained by adding 1 to 0]
The third figure — 2 [is obtained to be the one obtained by adding by 1 to 1]

The tenth figure — 9 [is assumed to be the above obtained by adding 1 to 8]

The eleventh figure? Now our unique figures have finished. We have
used it up all! So what will we do. Human thought: let’s use
the combination of two these 10 unique digits. So, 1 was combined
with 0 (these two are just two digits of in the set) → 10 becomes
the 11th figure & it is assumed to be the one obtained by adding 1 to 9.

Why not 01 was considered as 11th figure? Because human assumed
0 before leading 0 will make no value/meaning & can be ignored.
So 01 actually means 1.

Now, the next figure is obtained by adding 1 to 10. 1 has to be
written just below right most digit of 10
10
+1
______
11 Add it how we did add.

Similarly, to getting 20 from 19 will be —

 19
 +1               (we saw that adding 9+1 gives 10, but we write
————             right most digit & send rest to 0 as carry to left)
 20

We can see the following pattern being followed.

Now follow the similar logic for binary.
Write down the 2 different figures (digits) available for binary.

First figure — 0 [This is the OFF state in computer CPU circuits]

Now next digit coming will be the result of adding 1 to the digit.
And we have a separate unique digit for this i.e.
The second figure — 1 [is obtained by adding 1 to 0]
The third figure — 2 Now our set of {0,1} is all used up.
We don’t have another unique digit. So what will we do?
Again same thought as in decimal. So 1 is combined with 0 → thus 10
becomes the third figure. Sounds weird right? 1+1=10 🙂 Yes, but in
binary no. system, this is only true.
Why not 01 is considered as third figure because of the same reason — 0
(leading) does not make sense & can be omitted. Hence 01 simply means 1
even in computer’s world.

What about 4th figure in the binary?
Simple, how you did in decimal. Add 1 to 10.
10
+1
______
11

What about 5th figure in the binary?
Simple, how you did in decimal. Add 1 to 11.

Likewise, let’s write first 10 decimal & binary in two columns.

DecimalBinary
00
11
210
311
4100
5101
6110
7111
81000
91001
101010

So, from the above table we can say that the binary of 0 is 0, 1 is 1,
2 is 10, … 10 is 1010.

REMEMBER TRICK: If you want to write binary nos. counting, scan the
decimal nos. counting & jot down all the decimal nos. using
only 0 & 1.

Joke: There are 10 types of people in the world. One who understand
binary, others who don’t understand binary.

=> Addition of binary nos.
As we already saw, the addition in binary is simpler than decimal.

  • Basic principle of carry applies to both.
  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 10

Let’s add these two binary numbers:

  1000     [Apply above
+ 1001      rules]
——————
 10001

Let’s add these two binary numbers:

(carry: 0 1+1 1+1 1+1)
   1111
+  1111
————————
  11110

Test Yourself: Add following binary no.

 1111      11101         10
+1111    + 01010      + 1111
______   ________     _______
______   ________     _______ 

One point to note is this.
Just like when we add two decimal nos. say:

    5
  + 7
  ----
   12

If you add binary equivalent of 5 & 7, you will get binary equivalent
of 12.

Subtraction of binary nos.

Believe me subtraction in binary is simpler than decimal. You should
appreciate yourself & your small children in your family who have learnt
already subtraction in decimal no. They have done a great job.
Why is it simpler? Because in decimal nos., you are supposed to
deal with 10 digits but in binary you are supposed to deal with
2 digits only.
Let’s see how do we subtract in decimal nos —

      9
    — 1    This means to you go back from 9,
    -----    one time & you get the ans.
      8

Similarly:
9
– 3 This means you go back from 9 three times.
——- OR you subtract “1” three times.
6

       20        Since 0 is smaller than 1,
     —  1       you can't subtract, you
      ----          will have to take "1"
       19        from left digit. Hence
                 it becomes 10. 10-1 = 9

    

In binary, we can have only following combination while subtracting:

  • 1 — 1 = 0
  • 1 — 0 = 1
  • 0 — 0 = 0
  • 0 — 1 = You can’t subtract bigger from smaller digit. You will have
    to borrow 1 from left digit if it has, & thus 0 becomes 10.
    Hence 10 — 1 = 1 [Why? because 1+1=10]

Subtract:
11 110
-1 -10
—— ——
10 100

Just like we said in case of addition, when we subtract one decimal no.
from another decimal no., say:

      7       If you subtract binary equivalent of 5 from that of 7
    — 5       you will get binary equivalent
   ------
      2

Another name can be given to is “Make Yourself Confident”

Test Yourself:

1) 1000 2) 1001
— 111 — 011
———— ————

3) 11100
— 1010
————

=> Multiplication of binary nos.

In essence, multiplication is just another form of addition. In decimal:
4 x 2 means Add 4 to itself 2 times
=> 4+4+4
OR 3×4 => 3+3+3+3

We don’t need to be inefficient that we will add. We have multiplication
table in place to help us multiply.
In binary we can have only following combination while multiplication:

  • 0 x 0 = 0 You can think it 0, added
  • 0 x 1 = 0 0 times 1 time
  • 1 x 0 = 0 1 added 1 time.
  • 1 x 1 = 1

Again multiplication is simpler than that in decimal. We will multiply
just like how do we do in decimal.

 1000                 111

× 111 × 11
—————— ——————
1000 111
1000 x 111 x
1000 x x ——————
—————— 10101
111000

Make Yourself Checkup!

Test like said in addition & subtraction. When we multiply on decimal
no. we will get a combination binary complex.

Make Yourself Checkup!

 10101              101

× 111 × 11
—————— ——————

=> Division of binary nos.

Just like the multiplication is a form of addition, the division is a
creation of those basic mathematical concepts of subtraction. It is so
nicely similar (that) there are no mathematical symbols understood.

Addition — symbol is + . it is so. Just put one dot below
multiplication symbol (x) and it becomes division symbol (÷).

Subtraction — symbol is — . Just put one dot above it & one dot
below that line it becomes division symbol (÷).

In Ramayana, Karnam, Bharat & Shahbudin, what follows same. Karnam and
Ramayana add close bonding. They found close bonding.
— this k
— 1 x = 0 have close bonding

  • 1 x have close bonding

So for the divisor in binary, to exact, takes the divisor in decimal.
This is exactly the multiplication table is needed.

Divide:
2 ) — 6 Remainder
— 6 → quotient: we divide table 6/2 → quotient
72 quotient

We will first: 1011 ) 11010 — 101 | = 00110
First to divide by: 10 | 101 | 010

Let’s see the divisor → Quotient

Remainder is 1
Note: this remainder is also called remainder (!) also called machine
in computer world.

Now use go to 5 digits — so 10 is to the digit but it is small.
After 2 times left in called remainder. No. of times it is repeated
is called the remainder. N.O. of submultiply use 2 times can be
repeated in this can be arithmetic. So quotient is 2.
And quotient is ——

In Ramayana, Karnam, Bharat & Shahbudin, what follows same. Karnam and
Ramayana add close bonding. They found close bonding.
— this k
— 1 x = 0 have close bonding

  • 1 x have close bonding

Coming the division: means subtract 1 from 5.
That 6 ÷ 3 means subtraction is left after it goes 0 or less than 2.

3 times: 6, 3 means subtract 1 from 5.
Following the above, do 3 yet again follows:
Subtract 1 from 6 Three times
6
— 1 2nd time
——
5
— 1 1st time
——

This is still more the as equal to 3 three times.

As we get 0. At the end we cannot more than, this 0 is called
remainder. It proves N.O. of times it is repeated is called
the quotient. N.O. of submultiply use 2 times can be repeated.
So quotient is 2. Arithmetic: In this can it be repeated binary
arithmetic. And quotient is ——

CHECK WHETHER YOU UNDERSTOOD.

The numbers we discussed were all whole numbers. However, we will
also cover the same method you have discovered binary nos.
No. the same. The nos. → binary > 21?
Hmm, you also can be Fractional question for —
Are these yes but like all like to functional decimal. This is not
to use. Basically would like to do fractional. Put we would like
to be in real life to use fractional decimal. You might ask the position
for — no. Apply these will be in binary too?

This skill proved. So if start schema & 80 I can’t in 9th compute
99 2N5 in pm 785. For each math up the English’s partial.
Th. adding up Compute. Let’s understand.

For binary. Adding up then ALU & 978 needs if start compute.
No. The computers tells to the conversion atom. For understand
lets so ALU can add in binary before. So the conversion atom.
Arithmetic operations on do we perform binary
nos.

Make Yourself Confident!

1) 10 10101 2) 101001

Additions
nos: 10111 101
10011 101
10101 201
10100 110

Arithmetic operations on fractional binary no.

II Subtraction:
1100 110
100 – 110
111 – 111

III Multiplication:
10111 x
1011 x
110.0 x

 10100 110
 1001 01
 1011 101

IV Division:
1) 1011.01 (11.11 remainder 111) 110.01 (0.11)
Quotient

 2) 1011) 110101
    —  1111
     10111  111) 110.01  Quotient: (0.11)
     — 1011
       1001  Remainder is 1
       g111

 Remainder: — 10
               1 = 0

 Note: this remainder is also called remainder(!) 
 also called machine in computer world.

Next chapter: Conversion of decimal to binary vice-versa.

Previous Article
Next Article