Fundamental of Computers
Bhimsingh Bohara, Associate Professor
Department of Artificial Intelligence and Data
Science
Unit-3
Data Representation and Digital Logic
Learning Objectives
After completing this unit, students will be able to:
• Explain and convert between number systems: binary, decimal, octal,
hexadecimal
• Represent data formats (integers, floats, ASCII, images, audio) in binary
• Perform binary arithmetic: addition, subtraction, 1's and 2's complement
• Identify and apply logic gates (AND, OR, NOT, NAND, NOR, XOR, XNOR)
• Create truth tables and design gate-level logic
• Construct combinational circuits (half adder, full adder, MUX, DEMUX)
• Connect digital logic with real-world computing applications
Learning Outcomes
By the end of this Unit, students should be able to:
1. Convert between different number systems such as binary, decimal, octal, and
hexadecimal.
2. Represent and interpret data in formats such as integers, floating point,
characters (ASCII/Unicode), images, and audio.
3. Perform binary arithmetic operations including addition, subtraction, and
complements (1’s and 2’s).
4. Identify and apply logic gates (AND, OR, NOT, NAND, NOR, XOR, XNOR)
using truth tables.
5. Analyze and design basic combinational circuits such as half adders, full
adders, multiplexers, and demultiplexers.
6. Explain the role of digital logic in computer systems and how data is
processed at the hardware level.
Data Representation
The term data representation means the code
or technique in which the data can be
represented.
Number Systems
Number systems are very important to understand because
the design and organization of a computer depends on the
number systems. The four kind of number system used by the
digital computer –
1. Decimal number system
2. Binary number system
3. Octal number system
4. Hexadecimal number system
Decimal Number System
• The decimal number system consists of 10
digits namely 0 to 9.
• Since the decimal number system consists of
10 digits, the base or radix of this system is
10.
e.g. (405)10 , (145.25)10
Octal Number System
• The octal number system consists of 8 digits
namely 0 to 7.
• Since the Octal number system consists of 8
digits, the base or radix of this system is 8.
e.g (76)8 , (55.25)8
Binary Number System
• The binary number system consists of 2 digits
namely 0 and 1.
• Since the binary number system consists of 2
digits, the base or radix of this system is 2.
e.g. (101)2 , (1001.11)2
Hexadecimal Number System
• The Hexadecimal number system, popularly
known as Hex system has 16 symbols,
therefore its base/radix in 16.
• The 16 symbols used in Hexadecimal system
are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
e.g. (45)16, (11A)16
Conversion between Number Systems
➢ Decimal into Binary
Step 1. Divide the decimal number by the base of
binary using the repeated-division method.
Step 2. Note the remainder separately.
Step 3. Arrange the remainder in an order where
the first remainder noted is LSB/LSD and the last
remainder is MSB/MSB.
Decimal into Binary (Contd…)
Decimal into Octal
Decimal into Octal
Step 1. Divide the decimal number by the base
of octal using the repeated-division method.
Step 2. Note the remainder separately.
Step 3. Arrange the remainder in an order
where the first remainder noted is LSD and the
last remainder is MSB.
Decimal into Octal (Contd…)
Decimal into Hexadecimal
Step 1. Divide the decimal number by the
base of Hexadecimal using the repeated-
division method.
Step 2. Note the remainder separately.
Step 3. Arrange the remainder in an order
where the first remainder noted is LSD and
the last remainder is MSD.
Decimal into Hexadecimal (Contd…)
Decimal real number into Binary, Octal and Hexadecimal
Step 1. Multiply the fractional part by the base
of the numbers system (2, 8 or 16).
Step 2. Remove the whole number from the
product (the result oMf Dytics
tM
h/e multiplication) and
collect it separately.
Step 3. Repeat the step 1 and 2 with the new
fractional part till the fractional part becomes
zero.
Binary to Decimal
Any binary number can be converted into
decimal number using the weights
assigned to each [Link]/
A ics
e.g. (11011)2
• Its decimal equivalent is
• 1x24+1x23+0x22+1x21+1x20 = (27)10
Binary to Octal
1. Indirect Method:
Binary → Decimal → Octal
e.g. (11011)2
Its decimal equivalent is
1x24+1x23+0x22+1x21+1x20 = (27)10
And its Octal equivalent is (33)8 (division method)
Binary to Octal (Contd…)
2. Direct Method
Binary → Octal
Step 1: Make the group of 3-bits from right to left for
integer from left to right for fraction.
Step 2: Find decimal equivalent of each group.
Note: if the left most group (in integer) and the right most
group (in fraction) present with less than 3-bits make that
group by adding one or two zeros.
Binary to Octal (Contd…)
Direct Method: e.g.
Binary → Octal
e.g. (101111)2 = (? )8
(101111)2 = (57)8
Binary to Hexa
1. Indirect Method:
Binary → Decimal → Hexa
e.g. (11011)2
Its decimal equivalent is
1x24+1x23+0x22+1x21+1x20 = (27)10
And its Hexa equivalent is (1B)16 (Division method)
Binary to Hexa
2. Direct Method:
Binary → Hexa
Step 1: Make the group of 4-bits from right to left for integer
from left to right for fraction.
Step 2: Find decimal equivalent of each group.
Note: if the left most group (in integer) and the right most
group (in fraction) present with less than 4-bits make that
group by adding one, two or three zeros.
Binary to Hexa
Direct Method: e.g.
Binary → Hexa
e.g. (101111)2 = (? )16
(0010 1111)2 = (215)16 = (2F)16
Octal to Decimal
Any octal number can be converted into
decimal number using the weights
assigned to each bit.
e.g. (75)8
Its decimal equivalent is
7x81+5x80 = (61)10
Octal to Binary
Any octal number can be converted into binary
number by converting each bit of octal into its
equivalent 3-bit binary number.
e.g. (75)8
Its binary equivalent is (111101)2
Octal to Hexa
Octal → Binary → Hexa
Step1. Convert each digit of the octal into its 3 bit binary
equivalent.
Step2. Combine all the 3-bit binary equivalents to form the
entire binary sequence.
Step3. Make group of 4 bits staring from LSD. The extra zeros
for the completion of a group are placed at the leftmost end of
the number.
Step 4. Convert each of the 4-bit groups into their hexadecimal
equivalents.
Octal to Hexa (Contd…)
Octal → Binary → Hexa
Hexa to decimal
Hexa to binary
Binary representation of integers
• Binary equivalent of the integers are stored
in memory including one additional bit for
representing the sign of integers (positive or
negative).
• If the binary equivalent of the integer
includes one additional bit for representing
its sign, that binary number is called signed
binary number.
Binary representation of integers
There are three ways for representing the
positive and negative integers into its binary
equivalent.
1. Sign magnitude representation
2. One’s Complement
3. Two’s Complement
Binary representation of integers
1. Sign magnitude representation
In the sign magnitude representation, positive number
have a additional bit (sign bit) 0, while the negative
number has a sign bit 1, while the magnitude is a simple
binary equivalent of the number.
E.g. +5 and -5 can be representing in 6 bit register as:
+5 = 0 00101 and -5 = 1 00101
Binary representation of integers
Note: In every representation technique ,
the representation of positive number is
identical to that used in the sign
magnitude system i.e. simple binary form
including sign bit 0.
Binary representation of integers
2. One’s Complement representation
In one's complement, positive numbers are
represented as usual in signed magnitude.
However, negative numbers are represented
differently. To negate a number, replace all zeros
with ones, and ones with zeros - flip the bits.
+12 = 0 0001100, and -12 = 1 1110011.
Binary representation of integers
3. Two’s Complement representation
In two's complement, positive numbers are
represented as usual in signed magnitude.
However, negative numbers are represented by
adding 1 in magnitude part of one’s complement.
+12= 0 0001100
-12 = 1 1110011 (1’s complement)
-12 = 1 1110100 (2’s complement)
Binary Addition
Rule for Binary Addition:
➢ 0+0=0
➢ 0+1=1
➢ 1+0=1
➢ 1 + 1 = 0 (Carry 1)
Binary Addition
Example:
Add 110101 and 101111
1 1 0 1 0 1
1 0 1 1 1 1
1 1 0 0 1 0 0
More Examples…
Solve
1. (12)10 + (8)10
2. (15)10 + (10)10
3. (35)10 + (48)10
4. (10101)2 + (10110)2
5. (10111)2 + (11000)2
Logic Gates
What are logic gates?
• In the binary lesson, we discussed the switches inside a
computer
• Logic gates are the switches that turn ON or OFF
depending on what the user is doing!
• They are the building blocks for how computers work.
What are logic gates?
• Logic gates turn ON when a
certain condition is true, and
OFF when the condition is false
– They check whether or not the
information they get follows a
certain rule
• They either spit out the answer
true (ON) or false (OFF)
• Remember:
– True= ON = 1
– False = OFF=0
Let’ s do an example!
Logic
Gate
Let’ s do an example!
Types of Logic Gates!
• Major logic gates: NOT, AND, OR, and XOR
• There are also other ones, such as
NAND, NOR, and
• XNOR that we’ re not going to cover.
• This is called Boolean logic
• In a circuit schematic each logic gate is
represented by a different picture, like the
ones shown below.
NOT
• NOT is the most simple logic gate.
• All it does is take in an input that is either ON or OFF and
spits out the opposite.
• So for a 1 it will give a 0, and for a 0 it will give a 1 .
• Another name for a NOT gate is inverter, because it inverts
(makes opposite) the input
AND
• Unlike NOT, AND needs two inputs
• It only turns on when both inputs are ON
• If only one input is on, it spits out OFF
• If both inputs are off, it spits out OFF
AND Truth Table
• A convenient way to visualize the outputs for the logic gates
is through a truth table
• The truth table depicts the gate’ s response to each possible
set of inputs
Input 1
0 1
Input 2 0 0 0
1 0 1
Output
OR
• OR also needs two inputs
• OR needs one input to be ON for it to spit out ON
• It is also ON when both inputs are ON
• It is OFF when both inputs are OFF
OR Truth Table
Input 1
0 1
0 0 1
Input 2
1 1 1
Output
XOR
• XOR is the short way to say “Exclusive OR”
• Like OR, XOR also only needs one input to be ON for it to
spit out ON
• But unlike OR, when both inputs are ON, XOR spits
out OFF
• It is also OFF when both inputs are OFF
XOR Truth Table
Input 1
0 1
Input 2 0 0 1
1 1 0
Output
Stacking Logic Gates!
• An output of one logic gate can be an input to
another logic gate.
• This creates trees of gates that depend on each
other.
Let’ s Do an Example!
1 1
0
Example 2!
1
AND
1 0
0
Example 3!
1
1
1 AND
1 1 0
0
Logic gates actually look like weird bugs in
real life!
However, the diagrams we use are
easier to understand
[Link]