CO Unit 1-1
CO Unit 1-1
Components of Computer : Processor, Memory, input – output unit, difference between organization
and architecture, hardware software interaction,
Number system : concept of bit and byte, types and conversion,
Complement's : 1's complement, 2's complement,
Binary arithmetic : Addition, Overflow, Subtraction.
Computer: A computer is a combination of hardware and software resources which integrate together
and provides various functionalities to the user. Hardware are the physical components of a computer
like the processor, memory devices, monitor, keyboard etc. while software is the set of programs or
instructions that are required by the hardware resources to function properly.
There are a few basic components that aids the working-cycle of a computer i.e. the Input- Process-
Output Cycle and these are called as the functional components of a computer. It needs certain input,
processes that input and produces the desired output. The input unit takes the input, the central
processing unit does the processing of data and the output unit produces the output. The memory unit
holds the data and instructions during the processing.
Digital Computer: A digital computer can be defined as a programmable machine which reads the
binary data passed as instructions, processes this binary data, and displays a calculated digital output.
Therefore, Digital computers are those that work on the digital data.
Parts Of Processor :
Input Unit :The input unit consists of input devices that are attached to the computer. These
devices take input and convert it into binary language that the computer understands. Some of
the common input devices are keyboard, mouse, joystick, scanner etc.
Central Processing Unit (CPU) : Once the information is entered into the computer by the
input device, the processor processes it. The CPU is called the brain of the computer because it is
the control center of the computer. It first fetches instructions from memory and then interprets
them so as to know what is to be done. If required, data is fetched from memory or input device.
Thereafter CPU executes or performs the required computation and then either stores the output
or displays on the output device. The CPU has three main components which are responsible for
different functions – Arithmetic Logic Unit (ALU), Control Unit (CU) and Memory registers
Arithmetic Unit : The arithmetic unit, as its name suggests performs mathematical
calculations on data. Arithmetic calculations include addition, subtraction, multiplication
and division.
Logic Unit : Logic unit is a part of CPU that performs logical operations on the data.
Logical decisions involve comparison of two data items to see which one is larger or
smaller or equal. It performs 16 different types of logical operations, which include
greater than (>), less than (<), equal to (=), not equal to (!=), shift left, shift right etc.
Control Unit : The Control unit coordinates and controls the data flow in and out of CPU
and also controls all the operations of ALU, memory registers and also input/output units.
It is also responsible for carrying out all the instructions stored in the program. It decodes
the fetched instruction, interprets it and sends control signals to input/output devices until
the required operation is done properly by ALU and memory.
Memory Registers : A register is a temporary unit of memory in the CPU. These are
used to store the data which is directly used by the processor. Registers can be of
different sizes(16 bit, 32 bit, 64 bit and so on) and each register inside the CPU has a
specific function like storing data, storing an instruction, storing address of a location in
memory etc. The user registers can be used by an assembly language programmer for
storing operands, intermediate results etc. Memory Data Register (MDR) is used for
storing operands and data. Accumulator (ACC) is the main register in the ALU and
contains one of the operands of an operation to be performed in the ALU.
Memory : Memory attached to the CPU is used for storage of data and instructions and is called
internal memory The internal memory is divided into many storage locations, each of which can
store data or instructions. Each memory location is of the same size and has an address. With the
help of the address, the computer can read any memory location easily without having to search
the entire memory. when a program is executed, it’s data is copied to the internal memory and is
stored in the memory till the end of the execution. The internal memory is also called the
Primary memory or Main memory. This memory is also called as RAM, i.e. Random Access
Memory. The time of access of data is independent of its location in memory, therefore this
memory is also called Random Access memory (RAM). Read this for different types of RAMs
Output Unit : The output unit consists of output devices that are attached with the computer. It
converts the binary data coming from CPU to human understandable form. The common output
devices are monitor, printer, plotter etc.
Memory :
Memory is the most essential element of a computing system because without it computer can’t perform
simple tasks. Both types of memory (RAM and ROM) are important for the computer, but they serve
different purposes. RAM is used to store data that the computer is currently using, while ROM is used to
store data that the computer needs to boot and operate. RAM is faster than ROM, as the data stored in it
can be accessed and modified in any order, while data stored in ROM can only be read.
Computer memory is of two basic types:
1. Primary memory (RAM and ROM)
2. Secondary memory (Hard Drive, CD, etc).
Primary Memory
Primary Memory is a type of Computer Memory which is directly accessed by the Preprocessor. It is
basically used to store data on which computer is currently working. It has lesser storage than Secondary
Memory. It is basically of two types:
1. Random Access Memory (RAM)
2. Read Only Memory (ROM)
Random Access Memory (RAM) is a type of computer memory that is used to temporarily store data
that the computer is currently using or processing. RAM is volatile memory, which means that the data
stored in it is lost when the power is turned off. RAM is typically used to store the operating system,
application programs, and data that the computer is currently using.
It is also called read-write memory or the main memory or the primary memory.
The programs and data that the CPU requires during the execution of a program are stored in this
memory.
It is a volatile memory as the data is lost when the power is turned off.
Types of Random Access Memory (RAM)
1. Static RAM: SRAM stands for Static Random Access Memory. It is a type of semiconductor which
is widely used in computing devices and microprocessors.
2. Dynamic RAM: DRAM stands for Dynamic Random Access Memory. It is made of Capacitors and
has smaller data life span than Static RAM.
Speed: RAM is much faster than other types of storage, such as a hard drive or solid-state drive,
which means that the computer can access the data stored in RAM more quickly.
Flexibility: RAM is volatile memory, which means that the data stored in it can be easily
modified or deleted. This makes it ideal for storing data that the computer is currently using or
processing.
Capacity: The capacity of RAM can be easily upgraded, which allows the computer to store
more data in memory and thus improve performance.
Power Management: RAM consumes less power compared to hard drives, and solid-state
drives, which makes it an ideal memory for portable devices.
Disadvantages of Random Access Memory (RAM)
Volatility: RAM is volatile memory, which means that the data stored in it is lost when the
power is turned off. This can be a problem for important data that needs to be preserved, such as
unsaved work or files that have not been backed up.
Capacity: The capacity of RAM is limited, and although it can be upgraded, it may still not be
sufficient for certain applications or tasks that require a lot of memory.
Cost: RAM can be relatively expensive compared to other types of memory, such as hard drives
or solid-state drives, which can make upgrading the memory of a computer or device more
costly.
Read Only Memory (ROM) is a type of computer memory that is used to permanently store data that
does not need to be modified. ROM is non-volatile memory, which means that the data stored in it is
retained even when the power is turned off. ROM is typically used to store the computer’s BIOS (basic
input/output system), which contains the instructions for booting the computer, as well as firmware for
other hardware devices.
Stores crucial information essential to operate the system, like the program essential to boot the
computer.
It is non-volatile.
Always retains its data.
Used in embedded systems or where the programming needs no change.
Used in calculators and peripheral devices.
ROM is further classified into four types- MROM, PROM, EPROM, and EEPROM.
Types of Read-Only Memory (ROM)
1. PROM (Programmable Read-Only Memory)
2. EPROM (Erasable Programmable Read Only Memory)
3. EEPROM (Electrically Erasable Programmable Read Only Memory)
4. MROM (Mask Read Only Memory)
1. PROM (Programmable read-only memory): It can be programmed by the user. Once programmed,
the data and instructions in it cannot be changed.
2. EPROM (Erasable Programmable read-only memory): It can be reprogrammed. To erase data
from it, expose it to ultraviolet light. To reprogram it, erase all the previous data.
3. EEPROM (Electrically erasable programmable read-only memory): The data can be erased by
applying an electric field, with no need for ultraviolet light. We can erase only portions of the chip.
4. MROM(Mask ROM): Mask ROM is a kind of read-only memory, that is masked off at the time of
production. Like other types of ROM, mask ROM cannot enable the user to change the data stored in it.
If it can, the process would be difficult or slow.
Non-volatility: ROM is non-volatile memory, which means that the data stored in it is retained
even when the power is turned off. This makes it ideal for storing data that does not need to be
modified, such as the BIOS or firmware for other hardware devices.
Reliability: Because the data stored in ROM is not easily modified, it is less prone to corruption
or errors than other types of memory.
Power Management: ROM consumes less power compared to other types of memory, which
makes it an ideal memory for portable devices.
Limited Flexibility: ROM is read-only memory, which means that the data stored in it cannot be
modified. This can be a problem for applications or firmware that need to be updated or
modified.
Limited Capacity: The capacity of ROM is typically limited, and upgrading it can be difficult or
expensive.
Cost: ROM can be relatively expensive compared to other types of memory, such as hard drives
or solid-state drives, which can make upgrading the memory of a computer or device more
costly.
Difference between RAM and ROM
Read/Write Read and write operations are supported. Only read operations are supported.
CPU CPU can easily access data stored in CPU cannot easily access data stored
Interaction RAM. in ROM.
Size and Large size with higher capacity, Small size with less capacity,
Capacity concerning ROM. concerning RAM.
Cost RAM is more costlier than ROM. ROM is cheaper than RAM.
A RAM chip can store only a few A ROM chip can store multiple
Chip Size
gigabytes (GB) of data. megabytes (MB) of data.
Used for the temporary storage of data Used to store firmware, BIOS, and
Function
currently being processed by the CPU. other data that needs to be retained.
Secondary Memory
Secondary Memory is a type of Computer Memory which is used to permanently store the data and
Information. It has a larger data storage capacity than Primary Memory. Secondary Memory is not
directly accessible from CPU. It is basically of four types:
1. HardDisk
2. Compact Disc (CD)
3. Digital Versatile Disk (DVD)
4. Floppy Disk
Input Devices
Input devices are the devices that are used to send signals to the computer for performing tasks. The
receiver at the end is the CPU (Central Processing Unit), which has work to send signals to the output
devices. Some of the classifications of Input devices are:
Keyboard Devices
Pointing Devices
Mouse
Track ball
Touch screen
Light pen
Joystick
Scanning devices
Hand held scanner
Flat bed scanner
Drum scanner
Optical Recognition devices
OMR devices
OCR devices
MICR devices
Bar code reader
Digital camera
Voice recognition system
Media input devices
Output Devices
Output Devices are the devices that show us the result after giving the input to a computer system.
Output can be of many different forms like image, graphic audio, video, etc.
Display Monitors
CRT monitor
LCD monitor
TFT monitor
LED monitor
Printers
Impact Printers
Dot matrix
Diasy Wheel
Drum Printers
Non impact printers
Ink jet printers
Laser printers
Special purpose printers
Plotters
Drum Plotter
Flat bed Plotter
Ink jet Plotter
Electrostatic Plotter
Voice output systems
Projectors
In computing, input/ output or I/O is the communication between an information processing system,
such as a computer, and the outside world, possibly a human or another information processing system.
Inputs are the signals or data received by the system and the outputs are the signals or data sent from it.
The term can also be used as part of an action to " perform I/O" is to perform an input or output
operation. I/O devices are the pieces of hardware used by a human( or other system) to communicate
with a computer. For instance, a keyboard or computer mouse is an input device for a computer, while
monitors and printers are output devices. Devices for communication between computers, such as
modem and network cards, typically perform both input and output operations.
The designation of a device as either input or output depends on perspective. Mouse and
keyboards take physical movements that the human user outputs and convert them into input signals that
a computer can understand; the output from these devices is the computer's input. Similarly printers and
monitors take signals that a computer outputs as input, and they convert these signals into a
representation that human user can understand. From the human user's perspective the process of
reading or being these representation is receiving output, this type of interaction between computers and
human is studied in the field dof human computer interaction.
In computer architecture, the combination of the CPU and main memory, to which the CPU can
read or write directly using individual instructions is considered the brain of a computer. Any transfer of
information to or from the CPU/ memory combo, for example by reading data from a disk drive, is
considered I/O. The CPU and its supporting circuitry may provide memory-mapped I/O that is used in
low – level computer programming, such as in the implementation of device drivers or may provide
access to I/O channels. An I/O algorithm is one designed to explicit locatlity and perform efficiently
when exchanging data with a secondary storage device, such as disk drive.
Computer Architecture is a blueprint for design and implementation of a computer system. It refers to
the overall design of a computer system, including the hardware and software components that make up
the system and how they interact with each other.
Computer architecture provides the functional details and behavior of a computer system. It involves
the design of the instruction set, the microarchitecture, and the memory hierarchy, as well as the design
of the hardware and software components that make up the system.
Computer Architecture mainly deals with the functional behavior of a computer system and covers the
"What to do?" part. It gives the functional description of requirements, design, and implementation of
the different parts of a computer system.
In the designing process of a computer system, the computer architecture is to be defined before the
computer organization.
Although for using the computer one don’t really have to know how the hardware and software interact,
but for all these computer enthusiasts, this is surely interesting enough. It is a common fact that there are
a lot many differences between the hardware and software. But all these differences play their part in
building up the interaction between the hardware and software.
Software : The entire computer software can be broadly categorized into three parts : Device drivers,
operating system and application software. Simply all these types encompass the totality of the programs
present in your computer. Generally each and every program has its specific task to perform. For that
matter, the entire program is a set of instruction that are written to alter the state of hardware. Before
actually getting into how these instructions effect the hardware, here's something you need to understand
about computer hardware.
Hardware : The monitor, printer, hard drive, RAM, graphic card and all the other physical components
which are connected to the computer which can be physically touched, is the computer hardware.
Without hardware, software had no idea where to work on. Hence hardware and software run hand in
hand for implementing whatever the user wants.
There are a lot many differences between the hardware and software. Including the nature,
functionality and the ability to be changed again and again the software and hardware differ from each
other in numerous ways. But ultimately they are useless in the absence of the other. Once you perform
programming, using some high – level programming language (e.g. C or C#) the entire set of code you
write is converted into 1's and 0's. This is taken care of by the compiler which converts written code into
binary (1's and 0's) once the program follows a defined set of rules or the syntax. These 1's and 0's are
simply the voltage levels which establish the control over all the electric circuits.
For example, consider a simple LED bulb connected to a battery supply and a small switch.
Whenever this switch is closed the LED glows and once the switch is open the LED gets turned off. The
bulb glows and gets turned off because of the variation in voltage levels in these instances. When the
switch is closed the entire supply voltage is across the LED bulbs due to which it glows and once the
switch is open the bulb isn't supplied with the required voltage and hence it doesn't work. This is how
voltage levels control the LED bulb. The physical act of turning ON and OFF by opening and closing
the LED bulb can be substituted by any other mechanism. This works fine until this mechanism actually
is able to operate as per your requirement.
In case of computers, the entire hardware is supplied varying voltages due to which different
components get activated at the same or different time instances and achieve a particular task. Finally all
the binary data in a computer is nothing but the voltage level information, for which a particular task is
assigned to be executed.
The entire sequence of events that occur for hardware and software interaction is under the
control of Operating system. All the driver software help the Operating system to actually communicate
with the hardware, so as to execute the application software.
Number system :
The technique to represent and work with numbers is called number system. The number system is a
representation for a given number.
BIT : A bit is a binary digit, the smallest increment of data on a computer. A bit can hold only one of
two values: 0 or 1, corresponding to the electrical values of OFF or ON, respectively.
Because bits are so small, we rarely work with information one bit at a time. Bits are usually
assembled into a group of eight to form a byte.
The octal number system uses eight digits: 0,1,2,3,4,5,6 and 7 with the base of 8. The advantage of this
system is that it has lesser digits when compared to several other systems, hence, there would be fewer
computational errors. Digits like 8 and 9 are not included in the octal number system. Just like the
binary, the octal number system is used in minicomputers but with digits from 0 to 7. For example, 35 8,
238, and 1418 are some examples of numbers in the octal number system.
Decimal Number System
The decimal number system uses ten digits: 0,1,2,3,4,5,6,7,8 and 9 with the base number as 10. The
decimal number system is the system that we generally use to represent numbers in real life. If any
number is represented without a base, it means that its base is 10. For example, 72310, 3210, and
425710 are some examples of numbers in the decimal number system.
The hexadecimal number system uses sixteen digits/alphabets: 0,1,2,3,4,5,6,7,8,9 and A,B,C,D,E,F with
the base number as 16. Here, A-F of the hexadecimal system means the numbers 10-15 of the decimal
number system respectively. This system is used in computers to reduce the large-sized strings of the
binary system. For example, 7B316, 6F16, and 4B2A16 are some examples of numbers in the hexadecimal
number system.
Conversion of Number Systems
A number can be converted from one number system to another number system using number system
formulas. Like binary numbers can be converted to octal numbers and vice versa, octal numbers can be
converted to decimal numbers and vice versa, and so on. Let us see the steps required in converting
number systems.
1 * 20
1 * 21
1 * 22
0 * 23
0 * 24
1 * 25
Step 3: We just simplify each of the above products and add them.
1 0 0 1 1 1
1 * 20 = 1 * 1 = 1
1 * 21 = 1 * 2 = 2
1 * 22 = 1 * 4 = 4
0 * 23 = 0 * 8 = 0
0 * 24 = 0 * 16 = 0
1 * 25 = 1 * 32 = 32
----------
SUM 39
Here, the sum is the equivalent number in the decimal number system of the given number. Or, we can
use the following steps to make this process simplified.
100111 = (1 × 25) + (0 × 24) + (0 × 23) + (1 × 22) + (1 × 21) + (1 × 20)
= (1 × 32) + (0 × 16) + (0 × 8) + (1 × 4) + (1 × 2) + (1 × 1)
= 32 + 0 + 0 + 4 + 2 + 1
= 39
Thus, (100111)2 = (39)10.
1 1 0 0 0 0 1 0 0 =
6 0 4
Step 2 : Now we combine all the read parts in octal number
Thus, (110000100)2 = (604)8.
1 1 0 0 0 0 1 0 0 =
1 8 4
Step 2 : Now we combine all the read parts in hexadecimal number.
Thus, (110000100)2 = (184)16.
1 0 1 0 1 1 1 1 0 0
0 * 20 = 0 * 1 = 0
1
0*2 =0*2= 0
1 * 22 = 1 * 4 = 4
3
1*2 =1*8= 8
1 * 24 = 1 * 16 = 16
1 * 25 = 1 * 32 = 32
0 * 26 = 0 * 64 = 0
1 * 27 = 1 * 128=128
0 * 28 = 0 * 256= 0
1 * 29 = 1 * 512= 512
--------------
SUM - 700
Thus, (1010111100)2 = (700)10
Step 2: Convert the above number (which is in the decimal system), into the required number system
(hexadecimal).
Here, we have to convert 70010 into the hexadecimal system using the above-mentioned process. It
should be noted that in the hexadecimal system, the numbers 11 and 12 are written as B and C
respectively.
16 70
0 (which is C in hexadecimal)
16 43 12 (which is B in hexadecimal)
2 11
Example 1: Convert (300)10 into the binary number system with base 2.
Solution:
Step 1: Identify the base of the required number. Since we have to convert the given number into the
binary system, the base of the required number is 2.
Step 2: Divide the given number by the base of the required number and note down the quotient and the
remainder in the quotient-remainder form. Repeat this process (dividing the quotient again by the base)
until we get the quotient less than the base.
2 300
2 150 0
2 75 0
2 37 1
2 18 1
2 9 0
2 4 1
2 2 0
1 0
The equivalent number in the binary system is obtained by reading all the remainders and just the last
quotient from bottom to top as shown above.
Thus, (300)10 = (100101100)2
Step 3: The given number in the octal number system is obtained just by reading all the remainders and
the last quotient from bottom to top.
Step 3: The given number in the hexadecimal number system is obtained just by reading all the
remainders and the last quotient from bottom to top.
Therefore, (4285)10 = (10BD)16
1 4 4
4 * 80 = 4 * 1 = 4
4 * 81 = 4 * 8 = 32
4 * 82 = 4 * 64 = 64
----------
SUM = 100
Thus, (144)8 = (100)10
Example : Convert (5BC)16 into the decimal system.
Solution: 5BC16 is in the hexadecimal system. We know that B = 11 and C = 12 in the hexadecimal
system. So we get the equivalent number in the decimal system using the following process:
5 B C
= 5 11 12
12 * 160 = 12 * 1 = 12
1
11 * 16 = 12 * 16 = 176
5 * 162 = 12 * 256 = 1280
----------
SUM - 1468
Thus, (5BC)16 = (1468)10
Example : 4.25
Where 4 is an integral part and 0.25 is a fractional part.
Step 1 : Integral part (4)
- To convert an integral part into binary, just follow the usual method .
2 4
2 2 0
1 0
Example : 10.75
Integral part 10 = (1010)2
Fractional part (0.75)
0.75 * 2 = 1.50 // take 1 and move .50 to next step.
0.50 * 2 = 1.00 // take 1 and stop the process as there is no remainder.
Ans = (10.75)10 = (1010.11)2
Note : Some fractional part numbers will not end up with 1.0 with the above method. In floating storage,
the computer will allocate 23 bits for the fractional part. So its enough to do the above method at max 23
times.
Conversion of floating numbers into octal :
Example : 24.25
Where 24 is an integral part and 0.25 is a fractional part.
Step 1 : Integral part (24)
- To convert an integral part into octal, just follow the usual method .
8 2
4
3 0
Example : 20.00390625
Where 20 is an integral part and 0.00390625 is a fractional part.
Step 1 : Integral part (20)
- To convert an integral part into hexadecimal, just divide the number with 16 and write the remainder.
16 20
1 4
Example : (110.101)2
Step 1 : Convert the integral part of binary to decimal
a) Multiply each digit separately from left side of radix point till the first digit by 2 0, 21, 22, …so
on respectively.
b) Add all the result coming from step 1.
c) Equivalent integral decimal number would be the result obtained in step 2.
1 1 0
0 * 20 = 0 * 1 = 0
1 * 21 = 1 * 2 = 2
1 * 22 = 1 * 4 = 4
--------
6
Step 2 : Convert the fractional part of binary to decimal equivalent.
a) Divide each digit from right side of radix point till the end by 2-1, 2-2,2-3 ,2-4 …so on
respectively.
b) Add all the result coming from step 1.
c) Equivalent fractional decimal number would be the result obtained in step 2.
.101 = (1 * ½1) + (0 * ½2) + (1 * ½3)
= 1*0.5 + 0 * 0.25 + 1*0.125
= 0.625
So equivalent decimal to binary fractional is - (110.101)2 = (6.625)10
Example : (127.25)8
Step 1 : Convert the integral part of octal to decimal
a) Multiply each digit separately from left side of radix point till the first digit by 8 0, 81, 82, …so
on respectively.
b) Add all the result coming from step 1.
c) Equivalent integral decimal number would be the result obtained in step 2.
1 2 7
7 * 80 = 7 * 1 = 07
2 * 81 = 2 * 8 = 16
1 * 82 = 1 * 64 = 64
--------
77
Step 2 : Convert the fractional part of binary to decimal equivalent.
a) Divide each digit from right side of radix point till the end by 8-1, 8-2,8-3 ,8-4 …so on
respectively.
b) Add all the result coming from step 1.
c) Equivalent fractional decimal number would be the result obtained in step 2.
.25 = (2 * 1/81 ) + (5 * 1/82)
= 2 * 0.125 + 5 * 0.015625
= 0.25 + 0.078125 = .328125
So equivalent decimal to binary fractional is - (127.25)8 = (77.328125)10
Example : (12F.01B)16
Step 1 : Convert the integral part of hexadecimal to decimal
a) Multiply each digit separately from left side of radix point till the first digit by 16 0, 161, 162, …
so on respectively.
b) Add all the result coming from step 1.
c) Equivalent integral decimal number would be the result obtained in step 2.
1 2 F
F * 160 = 15 * 1 = 15
2 * 161 = 2 * 16 = 32
1 * 162 = 1 * 256 = 256
--------
293
Step 2 : Convert the fractional part of hexadecimal to decimal equivalent.
a) Divide each digit from right side of radix point till the end by 16-1, 16-2,16-3 ,16-4 …so on
respectively.
b) Add all the result coming from step 1.
c) Equivalent fractional decimal number would be the result obtained in step 2.
.01B = (0 * 1/161 ) + (1 * 1/162) + (B * 1/163)
= 0 * 0.0625 + 1 * 0.00390625 + 11 * 0.000244140625
= 0 + 0.00390625 + .00268554688 = 0.00659179688
So equivalent decimal to hexadecimal fraction is - (12F.01B)16 = (293.00659179688)10
Example : (13.54)8
Step 1 : In the integer part of octal take each digit and convert it to 3 bit binary equivalent number from
right to left and then place them side by side.
1 3
011
001
(13)8 = (001011)2
Step 2 : For the octal fraction take each digit and convert it to 3 bit binary equivalent number from left
to right and then place them side by side .
.5 4
100
101
(.54)8 = (101100)2
Step 3 : Combine the integral part and fraction part of octal to binary representation –
(13.54)8 = (1011.1011)2
Step 4 : Now we convert integer part of binary to hexadecimal by grouping 4 bits from the right most
side.
(1011)2 = (11)10 which is B in hexadecimal.
Step 5 : For the binary fractional part again group 4 bits starting from left side and convert it to
hexadecimal.
(.1011)2 = (11)10 which is B in hexadecimal.
(13.54)8 = (B.B)16
Complements :
Complements are used in digital computers for facilitating the subtraction operation and for logical
manipulation. There are two methods of complements for each base r system : the r's complement and
the (r-1)'s complement.
We can also do the above as 2's complement can be formed by leaving all least significant 0's and the
first 1 unchanged and replacing 1's with 0's and 0's with 1's in all other higher significant digits.
Binary arithmetic –
Binary is a base-2 number system that uses two states 0 and 1 to represent a number. We can also
call it to be a true state and a false state. A binary number is built the same way as we build a
normal decimal number. Binary arithmetic is an essential part of various digital systems. You can add,
subtract, multiply, and divide binary numbers using various methods. These operations are much easier
than decimal number arithmetic operations because the binary system has only two digits: 0 and 1.
Binary additions and subtractions are performed as same in decimal additions and subtractions.
When we perform binary additions, there will be two outputs: Sum (S) and Carry (C).
In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is written in the given column
and a carry of 1 over to the next column.
Example − Addition
0011010 + 001100
11 --- Carry
0011010 = 2610
+ 0001100 = 1210
----------------
0100110 = 3810
2. There are four rules for binary subtraction:
0011010 – 001100
11 --- Borrow
0011010 = 2610
+ 0001100 = 1210
----------------
0001110 = 1410
4. There are four parts in any division: Dividend, Divisor, quotient, and remainder.
Overflow :
When two numbers of n digits each are added and the sum occupies n+1 digits, we say that an
overflow occurred.
When the addition is performed with paper and pencil, an overflow is not a problem since there
is no limit to the width of the page to write down the sum.
An overflow is a problem in digital computers because the width of registers is finite.
A result that contains n+1 bits cannot be accomodated in a register with a standard length of n
bits.
When two unsigned numbers are added, an overflow is detected from the end carry out of the
most significant position.
In case of signed numbers, the leftmost bit always represents the sign (0 -- +ve, 1 -- -ve) and
negative numbers are in 2's complements from when two signed numbers are added, the sign bit
is treated as part of the number and the end carry does not indicate an overflow.
A 4 – bit number, for example, has range [0 … 15]. 4 – bit binary addition overflows if the result
exceeds 15. The fifth bit is discarded, producing an incorrect result in the remaining four bits.
Overflow can be detected by checking for a carry out of the most significant column.
Example: Compute (1101)2 + (0101)2
1101
0101
10010
The result overflows the range of a 4 bit binary number. If it must be stored as 4 bits the most
significant bit is discarded, leaving the incorrect result of 0010. If the computation had been done using
number with five or more bits, the result (10010)2, would have been correct.
An overflow cannot occur after an addition if one number is positive and other is negative.
An overflow may occur if the two numbers added are both positive or negative.
Example: 1 1 11
+ 70 0 1 0 0 0 1 1 0 - 70 1 0 1 1 1 0 1 0
+ 80 0 1 0 1 0 0 0 0 - 80 1 0 1 1 0 0 0 0
---------------------------- ----------------------------
+150 1 0 0 1 0 1 1 0 -150 0 1 1 0 1 0 1 0
Note that the 8 bit result that should have been positive has a negative sign bit and that should
have been negative has a positive sign bit.
The answer can't be accomodated with 8 bits, we say that an overflow occurred.
An overflow condition can be detected by observing the carry into the sign bit position and the
carry out of the sign bit position. If these two carries are not equal an overflow condition is
produced.
Case 1: Addition of the positive number with a negative number when the positive number has
a greater magnitude.
Initially, calculate the 1's complement of the given negative number. Sum up with the given
positive number. If we get the end-around carry 1, it gets added to the LSB.
Step 1 : First, find the 1's complement of the negative number 1001. So, for finding 1's
complement, change all 0 to 1 and all 1 to 0. The 1's complement of the number 1001 is 0110.
Step 2 : Now, add both the numbers, i.e., 1101 and 0110;
1101+0110=1 0011
Step 3 : By adding both numbers, we get the end-around carry 1. We add this end around carry
to the LSB of 0011.
0011+1=0100
Case 2: Adding a positive value with a negative value in case the negative number has a
higher magnitude.
Initially, calculate the 1's complement of the negative value. Sum it with a positive number. In this case,
we did not get the end-around carry. So, take the 1's complement of the result to get the final result.
Note: The resultant is a negative value.
Step 1: First find the 1's complement of the negative number 1110. So, for finding 1's
complement, we change all 0 to 1, and all 1 to 0. 1's complement of the number 1110 is 0001.
Step 2 : Now, add both the numbers, i.e., 1101 and 0001;
1101+0001= 1110
Step 3 : Now, find the 1's complement of the result 1110 that is the final result. So, the 1's
complement of the result 1110 is 0001, and we add a negative sign before the number so that we
can identify that it is a negative number.
Step 1 : Firstly find the 1's complement of the negative numbers 01101 and 01110. So, for
finding 1's complement, we change all 0 to 1, and all 1 to 0. 1's complement of the number
01110 is 10001, and 01101 is 10010.
Step 2 : Now, we add both the complement numbers, i.e., 10001 and 10010;
10001+10010= 1 00011
Step 3 : By adding both numbers, we get the end-around carry 1. We add this end-around carry
to the LSB of 00011.
00011+1=00100
Step 4 : Now, find the 1's complement of the result 00100 that is the final answer. So, the 1's
complement of the result 00100 is 110111, and add a negative sign before the number so that we
can identify that it is a negative number.
2) Subtraction using 1's complement - These are the following steps to subtract two binary numbers
using 1's complement
- In the first step, find the 1's complement of the subtrahend.
- Next, add the complement number with the minuend.
- If got a carry, add the carry to its LSB. Else take 1's complement of the result which will be
negative
Note: The subtrahend value always get subtracted from minuend.
We take 1's complement of subtrahend 00111, which comes out 11000. Now, sum them. So,
10101+11000 =1 01101.
In the above result, we get the carry bit 1, so add this to the LSB of a given result, i.e.,
01101+1=01110, which is the answer.
We take 1's complement of subtrahend 10111, which comes out 01000. Now, add both of the
numbers. So,
10101+01000 =11101.
In the above result, we didn't get the carry bit. So calculate the 1's complement of the result, i.e.,
00010, which is the negative number and the final answer.
Example 3: Subtract (6)10 from (3)10 using 1's complement method.
3) Addition using 2's complement - There are three different cases possible when we add two binary
numbers using 2's complement, which is as follows:
Case 1: Addition of the positive number with a negative number when the positive number has
a greater magnitude.
Initially find the 2's complement of the given negative number. Sum up with the given positive number.
If we get the end-around carry 1 then the number will be a positive number and the carry bit will be
discarded and remaining bits are the final result.
Step 1 : First, find the 2's complement of the negative number 1001. So, for finding 2's
complement, change all 0 to 1 and all 1 to 0 or find the 1's complement of the number 1001. The
1's complement of the number 1001 is 0110, and add 1 to the LSB of the result 0110. So the 2's
complement of number 1001 is 0110+1=0111
Step 2 : Add both the numbers, i.e., 1101 and 0111;
1101+0111=1 0100
Step 3 : By adding both numbers, we get the end-around carry 1. We discard the end-around
carry. So, the addition of both numbers is 0100.
Case 2: Adding of the positive value with a negative value when the negative number has a
higher magnitude.
Initially, add a positive value with the 2's complement value of the negative number. Here, no end-
around carry is found. So, we take the 2's complement of the result to get the final result.
Note: The resultant is a negative value.
Step 1: First, find the 2's complement of the negative number 1110. So, for finding 2's
complement, add 1 to the LSB of its 1's complement value 0001.
0001+1=0010
Step 2 : Add both the numbers, i.e., 1101 and 0010;
1101+0010= 1111
Step 3 : Find the 2's complement of the result 1110 that is the final result. So, the 2's
complement of the result 1110 is 0001, and add a negative sign before the number so that we can
identify that it is a negative number.
Case 3: Addition of two negative numbers
In this case, first, find the 2's complement of both the negative numbers, and then we will add both these
complement numbers. In this case, we will always get the end-around carry, which will be added to the
LSB, and forgetting the final result, we will take the2's complement of the result.
Note: The resultant is a negative value.
Example: -1101 and -1110 in five-bit register
Step 1 : Firstly find the 2's complement of the negative numbers 01101 and 01110. So, for
finding 2's complement, we add 1 to the LSB of the 1's complement of these numbers. 2's
complement of the number 01110 is 10010, and 01101 is 10011.
Step 2 : We add both the complement numbers, i.e., 10001 and 10010;
10010+10011= 1 00101
Step 3 : By adding both numbers, we get the end-around carry 1. This carry is discarded and the
final result is the 2.s complement of the result 00101. So, the 2's complement of the result 00101
is 11011, and we add a negative sign before the number so that we can identify that it is a
negative number.
4) Subtraction using 2's complement - These are the following steps to subtract two binary numbers
using 2's complement
We take 2's complement of subtrahend 00111, which is 11001. Now, sum them. So,
10101+11001 =1 01110.
In the above result, we get the carry bit 1. So we discard this carry bit and remaining is the final result
and a positive number.
We take 2's complement of subtrahend 10111, which comes out 01001. Now, we add both of the
numbers. So,
10101+01001 =11110.
In the above result, we didn't get the carry bit. So calculate the 2's complement of the result, i.e., 00010.
It is the negative number and the final answer.
Example 3: Subtract (110)2 from (1010)2 using 2's complement.
Minuend - 1010
Subtrahend - 0 1 1 0
2's complement of subtrahend is 1 0 0 1 + 1 = 1 0 1 0
So ,
1010
+ 1010
10100 Discard the carry, answer is 0 1 0 0 .
Minuend - 011
Subtrahend - 1 1 0
2's complement of subtrahend is 0 0 1 + 1 = 0 1 0
So,
011
+ 010
1 0 1 This is already in 2's complement. So, the answer is – 3.