KEMBAR78
Fundamentals of Computer Unit 2 | PDF | Binary Coded Decimal | Ebcdic
0% found this document useful (0 votes)
14 views16 pages

Fundamentals of Computer Unit 2

Uploaded by

saisahari2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views16 pages

Fundamentals of Computer Unit 2

Uploaded by

saisahari2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Unit II - Computer Codes: - Introduction - Decimal System - Binary System - Hexadecimal

System - Octal System - Binary Coded Decimal (BCD) Systems – Unicode.


Computer Arithmetic: - Introduction - Binary Addition - Binary Multiplication - Binary
Subtraction - Binary Division - Signed/unsigned Numbers - Complements of Binary Numbers -
Binary Subtraction Using Complements - Representing Numbers - Integer Arithmetic - Floating-
point Arithmetic

Computer Codes:
Introduction:
•A computer is a digital system that stores and processes different types of data in the
form of 0s and 1s. The different types of data handled by a computer system include
numbers, alphabets, and some special characters.
• The binary system represents each type of data in terms of binary digits, 0s and 1s.
• The decimal system is not the only number system used by computer users.
• All the number systems used by computer professionals to interact with computer
systems come under the category of positional number system. The positional number
system is a number system in which numbers are represented using some symbols
called digits and the values of these numbers can be determined by taking the position
of digits into consideration.
Category of number system:
• Decimal system
• Binary system
• Hexadecimal system
• Octal system

Decimal Number System


• The number system that we use in our day-to-day life is the decimal number system.
Decimal number system has base 10 as it uses 10 digits from 0 to 9.
• In decimal number system, the successive positions to the left of the decimal point
represent units, tens, hundreds, thousands, and so on.
• Each position represents a specific power of the base (10). For example, the decimal
number 1234 consists of the digit 4 in the units position, 3 in the tens position, 2 in the
hundreds position, and 1 in the thousands position.
Example:
(1 x 1000)+ (2 x 100)+ (3 x 10)+ (4 x l)
(1 x 103)+ (2 x 102)+ (3 x 101)+ (4 x l00)
1000 + 200 + 30 + 4
1234
As a computer programmer or an IT professional, you should understand the following number
systems which are frequently used in computers.

S.No. Number System and Description

Binary Number System


1 Base 2. Digits used : 0, 1
Octal Number System
2
Base 8. Digits used : 0 to 7

Hexa Decimal Number System


3
Base 16. Digits used: 0 to 9, Letters used : A- F

Binary Number System


Characteristics of the binary number system are as follows −
• Uses two digits, 0 and 1
• Also called as base 2 number system
• Each position in a binary number represents a 0 power of the base (2). Example
20
• Last position in a binary number represents a x power of the base (2). Example
2x where x represents the last position - 1.
Example
Binary Number: 101012
Calculating Decimal Equivalent −

Step Binary Number Decimal Number

Step 1 101012 ((1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20))10

Step 2 101012 (16 + 0 + 4 + 0 + 1)10

Step 3 101012 2110

Note − 101012 is normally written as 10101.


Some Technical Terms in Binary System
1. Bit. It is the smallest unit of information used in a computer system. It can either have
the value 0 or 1 Derived from the word Binary digit.
2. Nibble. It is a combination of 4 bits.
3. Byte. It is a combination of 8 bits. Derived from words ‘by eight’.
4. Word. It is a combination of 16 bits.
5. Double word. It is a combination of 32 bits.
6. Kilobyte (KB). It is used to represent the 1024 bytes of information.
7. Megabyte (MB). It is used to represent the 1024 KBs of information.
8. Gigabyte (GB). It is used to represent the 1024 MBs of information.
Octal Number System
Characteristics of the octal number system are as follows −
• Uses eight digits, 0,1,2,3,4,5,6,7
• Also called as base 8 number system
• Each position in an octal number represents a 0 power of the base (8). Example
80
• Last position in an octal number represents a x power of the base (8). Example
8x where x represents the last position - 1
Example
Octal Number: 125708
Calculating Decimal Equivalent −

Step Octal Number Decimal Number

Step 1 125708 ((1 x 84) + (2 x 83) + (5 x 82) + (7 x 81) + (0 x 80))10

Step 2 125708 (4096 + 1024 + 320 + 56 + 0)10

Step 3 125708 549610

Note − 125708 is normally written as 12570.


Hexadecimal Number System
Characteristics of the hexadecimal number system are as follows −
• Uses 10 digits and 6 letters, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
• Letters represent the numbers starting from 10. A = 10. B = 11, C = 12, D = 13,
E = 14, F = 15
• Also called as base 16 number system
• Each position in a hexadecimal number represents a 0 power of the base (16).
Example, 160
• The last position in a hexadecimal number represents a x power of the base (16).
Example 16x where x represents the last position - 1
Example
Hexadecimal Number: 19FDE16
Calculating Decimal Equivalent −

Step Binary Decimal Number


Number

Step 1 19FDE16 ((1 x 164) + (9 x 163) + (F x 162) + (D x 161) + (E x 160))10


Step 2 19FDE16 ((1 x 164) + (9 x 163) + (15 x 162) + (13 x 161) + (14 x 160))10

Step 3 19FDE16 (65536+ 36864 + 3840 + 208 + 14)10

Step 4 19FDE16 10646210

Note − 19FDE16 is normally written as 19FDE.


Binary Codes Decimal( BCD) Systems:
• The BCD system is employed by computer systems to encode the decimal number into
its equivalent binary number. This is generally accomplished by encoding each digit of
the decimal number into its equivalent binary sequence.
• The main advantage of BCD system is that it is a fast and efficient system for converting
the decimal numbers into binary numbers as compared to the pure binary system.
• The 4-bit BCD system is usually employed by the computer systems to represent and
process numerical data only. In the 4-bit BCD system, each digit of the decimal number
is encoded to its corresponding 4-bit binary sequence.

The two most popular 4-bit BCD systems are:


• Weighted 4-bit BCD code
• Excess – 3 (XS – 3) BCD code

Weighted 4-Bit BCD Code

• The weighted 4-bit BCD code is more commonly known as 8421 weighted code. It is
called weighted code because it encodes the decimal system into binary system by using
the concept of positional weighting into consideration. In this code, each decimal digit
is encoded into its 4-bit binary number in which the bits from left to right have the
weights 8, 4, 2, and 1 respectively.
Example Represent the decimal number 5327 in 8421 BCD code.
Solution
The given decimal number is 5327.
The corresponding 4-bit 8421 BCD representation of decimal digit 5 is 0101.
The corresponding 4-bit 8421 BCD representation of decimal digit 3 is 0011.
The corresponding 4-bit 8421 BCD representation of decimal digit 2 is 0010.
The corresponding 4-bit 8421 BCD representation of decimal digit 7 is 0111.
Therefore, the 8421 BCD representation of decimal number 5327 is 0101 0011 0010 0111.

Example: Convert the decimal number 87. 34 to 8421 BCD code.


Solution
The given decimal number is 87.34.
The corresponding 4-bit 8421 BCD representation of decimal digit 8 is 1000.
The corresponding 4-bit 8421 BCD representation of decimal digit 7 is 0111.
The corresponding 4-bit 8421 BCD representation of decimal digit 3 is 0011.
The corresponding 4-bit 8421 BCD representation of decimal digit 4 is 0100.
Therefore, the 8421 BCD representation of decimal number 87.34 is 1000 0111. 0011 0100.

Excess-3 BCD Code

• The Excess-3 (XS-3) BCD code does not use the principle of positional weights into
consideration while converting the decimal numbers to 4-bit BCD system. non-
weighted BCD code.
• The function of XS-3 code is to transform the decimal numbers into their corresponding
4-bit BCD code.
• In this code, the decimal number is transformed to the 4-bit BCD code by first adding
3 to all the digits of the number and then converting the excess digits.

Example Convert the decimal number 85 to XS-3 BCD code.


Solution
The given decimal number is 85.
Now, add 3 to each digit of the given decimal number as:
8 + 3 = 11
5+3=8
The corresponding 4-bit 8421 BCD representation of the decimal digit 11 is 1011.
8-BIT BCD SYSTEMS

• The 8-bit BCD systems were developed to overcome the limitations of 6-bit BCD
systems. The 6-bit BCD systems can handle numeric as well as non-numeric data but
with few special characters.
• The 8-bit BCD systems can handle numeric as well as non-numeric data with almost
all the special characters such as +, - , *, /, @, $, etc. Therefore, the various codes under
the category of 8-bit BCD systems are also known as alphanumeric codes.
The three most popular 8-bit BCD codes are:
• Extended Binary Coded Decimal Interchange Code (EBCDIC)
• American Standard Code for Information Interchange (ASCII)
• Gray code

EBCDIC Code
• The EBCDIC code is an 8-bit alphanumeric code that was developed by IBM to
represent alphabets, decimal digits, and special characters, including control characters.
• Control characters are the special characters that are used to perform a specific function.
• For example, the control character FF is used to feed the next page into the printer or
eject the current page from the printer.
• The EBCDIC codes are generally the decimal and the hexadecimal representation of
different characters. This code is rarely used by non IBM-compatible computer
systems.
ASCII Code
• The ASCII code is pronounced ASKEE and is used for the same purpose for which the
EBCDIC code is used. However, this code is more popular than the EBCDIC code as
unlike the EBCDIC code this code can be implemented by most of non-IBM computer
systems. Initially, this code was developed as a 7-bit BCD code to handle 128 characters
but later it was modified to an 8-bit code.
Gray Code
• Gray code is another important code that is also used to convert the decimal number
into the 8-bit binary sequence. However, this conversion is carried out in a manner that
the contiguous digits of the decimal number differ from each other by one bit only.

convert the Gray-coded number to its binary equivalent by remembering the following two
major rules:
• The Most significant bit (MSB) of the Gray coded number and the equivalent binary
number is
always the same.
• The next-to-most significant bit of the binary number can be determined by adding the
MSB of the
binary number to the next-to-most significant bit of the gray coded number.

Unicode
Unicode is an international coding system designed to be used with different language scripts.
Each character or symbol is assigned a unique numeric value, largely within the framework of
ASCII. Earlier, each script had its own encoding system, which could conflict with each other.
Computer Arithmetic:
Introduction:
• A computer system stores and processes billionsof instructions in a second that
involves a lot of arithmetic computations.
• The different arithmetic operations in the computer system are performedby the
Arithmetic and Logic Unit (ALU), which is an important component of the CPU.
Besides performing arithmetic operations, the ALU of the computer system also
performs various logical operations.
• The computer arithmetic is also referred as binary arithmetic because the computer
system stores and processes the data in the binary form only.
• The binary arithmetic operations are usually simpler to carry out as compared to the
decimal operations because one needs to dealwith only two digits, 0 and 1, in the
binary operations.
o Binary addition
o Binary multiplication
o Binary subtraction
o Binary division
• Binary Addition: Rules

c B A+B Carr
y
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Example: Perform the binary addition operation on the following binary numbers:
0010
0111
Solution
The given binary numbers are 0010 and 0111.
Now, perform the binary addition of the given numbers as:
Binary number Decimal value
0 0 1 0 2
0 1 1 1 7
1 0 0 1 9
Therefore, the result of the binary addition performed on 0010 and 0111 is 1001.
Rules for adding three binary numbers

A B C A+B+ Carr
C y
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

Example Perform the binary addition operation on the following three numbers:
0 0 1 0
0 0 0 1
0 1 1 1
Solution
The given binary numbers are 0010, 0001 and 0111.
Now, perform the binary addition of the given numbers as:
Binary number Decimal value

0 0 1 0 2
0 0 0 1 1
0 1 1 1 7
10 1 0 10

• Binary Multiplications:
Multiplications Rules

Example: Perform the binary multiplication of the decimal numbers 12 and 10.
Solution
The equivalent binary representation of the decimal number 12 is 1100.
The equivalent binary representation of the decimal number 10 is 1010.
Now, perform the binary multiplication of the given numbers as:
• Binary Subtraction:
Rules

Example Subtract the following binary numbers:


0101
0010

• Binary Division:
• The following are the two important points, which need to be remembered while
performing the binary division:
• If the remainder obtained by the division process is greater than or equal to
the divisor, put 1 in the quotient and perform the binary subtraction.
• If the remainder obtained by the division process is less than the divisor, put
0 in the quotient and append the next most significant digit from the dividend
to the remainder.

Example: Divide 14 by 7 in binary form.


Solution
The equivalent binary representation of the decimal number 14 is 1110.
The binary representation of 7 is 111.
Now, perform the binary division of the given numbers as:
signed magnitude numbers:

• In binary number system, both +ve and –ve values are possible.
• In this, we use 0’s and 1’s to represent every number. The representation of number is
known as signed number.

0 --> +ve number

1 --> -ve number

E.g.
+7 = 0111

-7 = 1111

This kind of representation for signed number is called signed magnitude representation.

Note: For +ve numbers, the result is the same as the unsigned binary representation.

The signed numbers are represented in three ways: Sign-magnitude form, 1’s complement
form and 2’s complement form

1. Sign-Magnitude form
In this form, a binary number has a bit for a sign symbol. If this bit is set to 1, the number
will be negative else the number will be positive if it is set to 0. Apart from this sign-bit,
the n-1 bits represent the magnitude of the number.
Syntax:
Sign Bit Actual binary

E.g. +7 = 0111
-7 = 1111

2. 1's Complement
By inverting each bit of a number, we can obtain the 1's complement of a
number. The negative numbers can be represented in the form of 1's complement. In this
form, the binary number also has an extra bit for sign representation as a sign-magnitude
form.
Syntax:
Sign Bit 1’s complement of the actual binary

E.g. 7 = 111
1’s complement = 000
- 7 = 1000
3. 2's Complement
By inverting each bit of a number and adding plus 1 to its least significant bit, we
can obtain the 2's complement of a number. The negative numbers can also be
represented in the form of 2's complement. In this form, the binary number also has an
extra bit for sign representation as a sign-magnitude form.
Syntax:
Sign Bit 2’s complement of actual binary

E.g. 7 = 111
1’s complement = 000
2’s complement = 000 + 1 = 001
- 7 = 1001

Binary Data Representation


A binary number may also have a binary point, in addition to the sign. The binary point
is used for representing fractions, integers and integer-fraction numbers. Registers are high-
speed storage areas within the Central Processing Unit (CPU) of the computer. All data are
brought into a register before it can be processed. For example, if two numbers are to be added,
both numbers are brought in registers, added, and the result is also placed in a register. There
are two ways of representing the position of the binary point in the register—fixed point number
representation and floating point number representation.

Fixed point number representation


• The fixed point number representation assumes that the binary point is fixed at one
position either at the extreme left to make the number a fraction, or at the extreme
right to make the number an integer.
The integer binary signed number is represented as follows:

• For a positive integer binary number, the sign bit is 0 and the magnitude is a positive
binary number.
• For a negative integer binary number, the sign bit is 1. The magnitude is represented
in any one of the three ways:-
· Signed Magnitude Representation—The magnitude is the positive binary number
itself.
· Signed 1 ’s Complement Representation—The magnitude is the 1’s complement
of the positive binary number.
· Signed 2’s Complement Representation—The magnitude is the 2’s complement
of the positive binary number.
Addition of Signed Binary Numbers:
The addition of any two signed binary numbers is performed as follows:-
• Represent the positive number in binary form.(For example, +5 is 0000 0101 and
+10 is 0000 1010)
• Represent the negative number in r’s complement form. (For example, -5 is
11111011 and -10 is 1111 0110).
• Add the bits of the two signed binary numbers.
• Ignore any carry out from the sign bit position.
E.g.
Add +5 and +10
+5 in binary form i.e., 0000 0101
+10 in binary form, i.e., 0000 1010

Add −5 and +10


−5 in 2’s complement form is 1111 1011
+10 in binary form is 0000 1010

Add +5 and −10


+5 in binary form is 0000 0101
−10 in 2’s complement form is 1111 0110
Subtraction of Signed Binary Numbers:
The subtraction of signed binary numbers is changed to the addition of two signed numbers.
For this, the sign of the second number is changed before performing the addition operation.

Floating Point Number Representation

• The floating point number representation uses two registers. The first register stores
the number without the binary point. The second register stores a number that
indicates the position of the binary point in the first register.
• The floating point representation of a number has two parts: mantissa and exponent.
The mantissa is a signed fixed point number. The exponent shows the position of the
binary point in the mantissa.
For example, the binary number +11001.11 with an 8−bit mantissa and 6−bit exponent is
represented as follows:-
Ø Mantissa is 01100111. The left most 0 indicates that the number is positive.
Ø Exponent is 000101. This is the binary equivalent of decimal number + 5.

The floating point number is Mantissa x 2exponent i.e., + (.1100111) x 2+5.

You might also like