You are on page 1of 23

KANDASWAMI KANDAR’S COLLEGE, VELUR

DEPARTMENT OF COMPUTER SCIENCE

Class: I B.SC(CS) & BCA Unit: III


Paper Name: COA

UNIT - III
Number Systems and Codes: Binary Number System – Binary-to-decimal Conversion – Decimal-to
binary Conversion – Octal Numbers – Hexadecimal Numbers – The ASCII Code – The Excess-3
Code – The Gray Code. Arithmetic Circuits: Binary Addition –Binary Subtraction –Unsigned Binary
Numbers – Sign-magnitude Numbers - 2'S Complement Representation - 2'S Compliment
Arithmetic.

NUMBER SYSTEMS AND CODES:


• Understanding digital systems requires an understanding of the decimal, binary, octal,
and hexadecimal numbering systems.
– Decimal – 10 symbols (base 10)
– Hexadecimal – 16 symbols (base 16)
– Octal – 8 symbols (base 8)
– Binary – 2 symbols (base 2)

BINARY NUMBER SYSTEM:


The binary number system is a system that uses only the digits 0 and 1 as codes. All other digits (2 to
9) are not used. To represent decimal numbers and letters of the alphabet with the binary code, you
have to use different strings of binary digits for each number or letter.

Decimal Odometer:
The number system is having digit 0, 1, 2, 3, 4, 5, 6, 7, 8, 9; this number system is known as a
decimal number system because total ten digits are involved. The base of the decimal number system
is 10.

1
Binary Odometer:
The modern computers do not process decimal number; they work with another number system
known as a binary number system which uses only two digits 0 and1.The base of binary number
system is 2 because it has only two digit 0 and 1.The digital electronic equipments are works on the
binary number system and hence the decimal number system is converted into binary system.

The word bit is the abbreviation for binary digit. When a binary number has 4 bits, it is sometimes
called a nibble. A binary number with 8 bits is known as a byte; this has become the basic unit of
data used in computers. Table is a list of 4-bit number from 0000 to 1111.

2
BINARY-TO-DECIMAL CONVERSION:
The decimal number system is represented by the digit 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. It consist ten digits
and hence the base of the system is 10. Their base is increased by the factor of 10.
The binary number system consist only two digits 1 and 0.The base of the binary number system is
2, and it is increased by the factor of two.

Positional Notation and Weights:


The first digit has 20 weights, the second has 21 weights, the weight of the third digit is 22 and so on.
For instance, decimal number 2945 may be written as
2945 = 2000 + 900 + 40 + 5
In powers of 10, this becomes
2945 = 2(103) + 9(102) + 4(101) + 5(100)
The decimal number system is an example of positional notation, each digit position has a weight or
value.

Binary Weights:
We can rewrite any binary number in terms of weights. For instance, binary number 111 becomes
111=100+10+1
In decimal numbers, this may be rewritten as
7=4+2+1
Each digit position in a binary number has a weight. The least significant digit (the one on the right)
has a weight of 1. The second position from the right has a weight of 2; the next, 4; and then 8, 16,
32, and so forth.
3
These weights are in ascending powers of 2; therefore, we can write the foregoing equation as
7= 1(22) + 1(21) + 1(20)

Considered the conversion of the binary number 10101 into its equivalent decimal numbers

Examples:
1. Binary number 101 has a decimal equivalent of
4+0+1=5
2. Binary number 1101 is equivalent to
8+4+0+1=13
3. Binary number 1100 l, is equivalent to
16 + 8 + 0 + 0 + 1 = 25

Streamlined Method
We can streamline binary-to-decimal conversion by the following procedure:
1. Write the binary number.
2. Directly under the binary number write 1, 2, 4, 8, 16 ... , working from right to left.
3. If a zero appears in a digit position, cross out the decimal weight for that position.

4
4. Add the remaining weights to obtain the decimal equivalent.
As an example of this approach, let us convert binary 101 to its decimal equivalent:
STEP 1: 101
STEP 2: 4 2 1
STEP 3: 4 2 1
STEP 4: 4 + 1 = 5
As another example, notice how quickly 10101 is converted to its decimal equivalent:
1010 1
16 8 4 2 1 21

Binary to Decimal Conversion for Fractional Number:


For a fractional number, the weights of the digit position to the right of binary point are given by 2-1,
2-2, 2-3, 2-4… etc. Consider the conversion of a fractional binary number.0101 into its equivalent
decimal numbers.

After disregarding the weight 2-1 and 2-3 and summing up the remaining weights, i.e., we get the
decimal number 0.3125.

Binary to Decimal Conversion for Mixed Number


The number with an integer and fractional part are called mixed number. The weight for a mixed
number can be written as

Consider the conversion of a binary number 1101.101 into its equivalents decimal number

5
After disregarding the weight 21 and 2-2 and on summing up the remaining weights the required
decimal number is 13.625.

DECIMAL-TO BINARY CONVERSION:


The most popular way to convert a decimal number into the binary is the double dabble method. In
this method, the given decimal number is progressively divided by 2 and writing the remainder after
each division. When all the remainder is read in reverse order, the binary number is obtained.

Double Dabble:
Step 1: Divide the decimal number by 2, which is the base of the binary number
Step 2: The remainder which is obtained from step 1 is the least significant bit of the new binary
number.
Step 3: Divide the quotient which is obtained from the step 2 and the remainder obtained from this is
the second least significant bit of the binary number.
Step 4: Repeat the process until the quotient remains zero.
Step 5: The last remainder obtained from the division is the most significant bit of the binary
number. Hence arrange the number from most significant bit to the least significant bit (i.e., from
bottom to top).

6
For example – Consider the conversion of the decimal number 25 into its equivalent binary.

Conversion of Decimal to Binary for Fraction Number


For fractional decimal numbers, multiply it by 2 and record the carry in the integral position. The
carries when read down produces the equivalent binary fraction as explained by the example given
below.
Consider the fractional binary number 0.35

Thus the fractional binary number is .01011, i.e., 0.01011.


The process of multiplication by 2 will continue till the desired accuracy is achieved.

OCTAL NUMBERS:
The base of a number system is equal to the number of digits used, i.e., for decimal number system
the base is ten while for the binary system the base is two. The octal system has the base of eight as
it uses eight digits 0, 1, 2, 3, 4, 5, 6, 7.

Octal Odometer:
All these digits from 0 to 7 have the same physical meaning as by decimal symbols, the next digit in
the octal number is represented by 10, 11, 12, which are equivalent to decimal digits 8, 9, 10
respectively. In this way, the octal number 20 will represent the decimal digit and subsequently, 21,
22, 23.. Octal numbers will represent the decimal number digit 17, 18, 19… etc. and so on.

7
Octal Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
For example, the octal number 3456 is 011 100 101 110 in binary.

Octal to Decimal Conversion


In octal number system, each digit position has the weight eight regarding power eight shown in the
figure below.

Example – Consider the octal number 354.42 into its equivalent decimal number. The integer part
354 converts to octal shown below.

And the fractional parts 0.42 convert to octal

The decimal number system is 236.53125.

Decimal to Octal Number Conversion:


For converting the decimal numbers into an octal number, the octal dabble method is used. In the
octal double method, the integer octal number is divided by the digit 8. And for converting the
fractional decimal number into an octal number, it is multiplied by the digit 8 and record the carry.
When these carry read down, it gives the fractional octal number.
Example: Consider the conversion of the decimal number 236.53. The conversion of integer part is
shown below.

8
And the fraction part

Thus the octal number is 354.4172.

Octal to Binary Conversion:


The base of the octal number system (8) is the third power of base of a binary system (2), the
interconversion of octal and a binary number is very simple and direct as explained below.
Let converting the octal number 35.346 to its equivalent binary number

Thus the required binary number is 011 101. 011 100 110

Binary to Octal Conversion:


The conversion of binary to octal is a reversal of the above procedure. For example, the binary
number 010100111.100011 can be converted into an octal number by first written the bits in the
group of three and then awarding the decimal number of to each of the group of three bits as shown
below.

9
Thus the required octal number is 257.43
HEXADECIMAL NUMBERS:
These numbers are used extensively in microprocessor work. The hexadecimal number system has a
base of 16, and hence it consists of the following sixteen number of digits.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
The size of the hexadecimal is much shorter than the binary number which makes them easy to write
and remember. Let 0000 to 000F representing hexadecimal numbers from zero to fifteen.
Decimal Binary Octal Hexadecimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Hexadecimal to Binary Conversion Method
To convert a hexadecimal number to a binary number, convert each hexadecimal digit to its four
digit equivalent.

10
The hexadecimal number systems are easily converted into a binary system by using the method
explains below.

For example, consider the hexadecimal number 9AF which is converted into a binary digit. The
conversions are explained below.

Therefore the equivalent binary number is 1001 1010 1111.


Binary to Hexadecimal Conversion:
To convert the given binary number into its equivalent hexadecimal number rewrite the binary
number of the sets of four digits and then place the hexadecimal digit in front of each four digit set
of a binary number as explained by the following number.

Thus the equivalent hexadecimal number is E8D6.

Hexadecimal to Decimal Conversion Method


The base of the hexadecimal number system is 16, therefore the weights corresponding to various
positions of the digits will be as shown below.

For instance, consider the conversion of hexadecimal number E8F6.27 into its equivalent binary
number.

11
Decimal to Hexadecimal Conversion Method:
The conversion of the given decimal number into hexadecimal number requires the application
of hex-dabble method which is similar to the double-dabble method with the exception that one has
to divide the given number by 16 instead of 2.
Consider the conversion of the decimal number 3749 into its hexadecimal equivalent number.

The third reminder 13 is equivalent to D in a hexadecimal number system. Thus the equivalent
hexadecimal number D97
THE ASCII CODE:
 Alphanumeric codes is the set of elements that includes 10 decimal digits, 26 letter of alphabets
in a number of special characters such as $, +, α etc.
 The standard alphanumeric binary code is the ASCII
 The full form of ASCII code is American Standard Code for Information Interchange. It is a
seven bit code based on the English alphabet.
 This code allows manufacturers to standardize computer hardware such as keyboards, printers,
and video displays.
 It is 7-bit or 8-bit alphanumeric code.
 7-bit code is standard ASCII supports 127 characters.
 The ASCII code is a 7-bit code whose format is
X6X5X4X3X2X1X0
where each X is a 0 or a 1.

12
For example, the table shows that the capital letter A has an X6X5X4 of 100 and an X3X2X1X0of
0001.
The ASCII code for A is, 1000001
For easier reading, we can leave a space as follows:
100 0001 (A)
The letter a is coded as
110 0001 (a)
More examples are
110 0010 (b)

Parity Bit:
To catch these errors, a parity bit is usually transmitted along with the original bits. Then a parity
checker at the receiving end can test for even or odd parity, whichever parity has been prearranged
between the sender and the receiver. Since ASCII code uses 7 bits, the addition of a parity bit to the
transmitted data produces an 8-bit number in this format:

This is an ideal length because most digital equipment is set up to handle bytes of data.

EBCDIC as Alphanumeric Code:


 The EBCDIC stands for Extended Binary Coded Decimal Interchange Code. IBM invented this
code to extend the Binary Coded Decimal which existed at that time.
 It was mainly used in IBM mainframe computers.

13
 Here, the binary codes of letters and numerals come as an extension of BCD code. The bit
assignments of EBCDIC are different from the ASCII but the character symbols are the same.

THE EXCESS-3 CODE:


The excess-3 code is an important 4-bit code sometimes used with binary-coded decimal (BCD)
numbers. To convert any decimal number into its excess-3 form, add 3 to each decimal digit, and
then convert the sum to a BCD number.
The Excess-3 code words are derived from the 8421 BCD code words adding (0011)2 or (3)10 to each
code word in 8421. The excess-3 codes are obtained as follows:

Example

1. Convert 29 to an excess-3number:

After adding 9 and 3 do not carry the 1 into the next column; instead, leave the result intact as 12,
and then convert as shown. Therefore, 0101 1100 in the excess-3 code stands for decimal 29.

2. Convert 12 to an excess-3 number. First, add 3 to each decimal digit:

Second, convert the sum to BCD form:

14
So, 0100 0101 in the excess-3 code stands for decimal 12.

THE GRAY CODE:


It has a very special feature that has only one bit will change, each time the decimal number is
incremented as shown in fig. As only one bit changes at a time, the gray code is called as a unit
distance code. The gray code is a cyclic code. Gray code cannot be used for arithmetic operation.

 Gray code for 2 is 0011 and for 3 is 0010.


 No weights are assigned to the bit positions.
Applications of Gray code
 Gray code is popularly used in the shaft position encoders.
 A shaft position encoder produces a code word which represents the angular position of the
shaft.

15
ARITHMETIC CIRCUITS:
Circuits that can perform binary addition and subtraction are constructed by combining logic gates.
These circuits are used in the design of the arithmetic logic unit (ALU). The electronic circuits are
capable of very fast switching action, and thus an ALU can operate at high clock rates.

BINARY ADDITION:
Arithmetic rules for binary numbers are quite straightforward, and similar to those used in decimal
arithmetic. The rules for addition of binary numbers are:

Note that in the case of 1+1, a carry results into the next bit to the left.
In truth table form, the addition of two bits, a + b is:

Observe that a + b is identical to the logical XOR operation and that carry is the same as the logical
and operation.

Simple Binary Addition

BINARY SUBTRACTION:
The four fundamental steps of binary subtraction are

Suppose, A = 10101100 and B = 1010100 and we want to find out A - B Now implementing the
rules of binary subtraction

16
UNSIGNED BINARY NUMBERS:
 An unsigned binary numbers is a fixed-point system with no fractional digits.
 Unsigned binary numbers are modulo number systems, usually with a modulus which is a power
of 2.
 A 4-bit unsigned binary number has values ranging from 00002 (010) to 11112 (1510).
 The 8-bit unsigned binary number is from 0000 0000, to 1111 1111.
 Modern computers typically support binary integers of 8, 16, 32, or 64 bits.
Bits Range
8 0 to 28-1 (255)
16 0 to 216-1 (65,535)
32 0 to 232-1 (4,294,967,295)
64 0 to 264-1 (18,446,744,073,709,551,615 = 1.844674407 x 1019

Overflow: In 8-bit arithmetic, addition of two unsigned numbers whose sum is greater than 255
causes an overflow, a carry into the ninth column. Most microprocessors have a logic circuit called a
carry flag; this circuit detects a carry into the ninth column and warns you that the 8-bit answer is
invalid.

SIGN-MAGNITUDE NUMBERS:
 The foregoing numbers contain a sign bit followed by magnitude bits. Numbers in this form are
called sign-magnitude numbers.
 To represent a number in sign-magnitude, we simply use the leftmost bit to represent the sign,
where 0 means positive, and the remaining bits to represent the magnitude (absolute value).
 An 8-bit sign-magnitude number would appear as follows:
Sign Bit Magnitude Bits

17
Sign Bit Magnitude Bits
7 6-0

Some examples of converting sign-magnitude numbers:


+7  0000 0111
-16 1001 0000
+25 0000 0000 0001 1001
-128 1000 0000 1000 0000
Range of Sign-Magnitude Numbers:
Since the magnitude is an unsigned binary number, range is computed as it is for unsigned binary,
but with one less bit. Hence, for 8-bit sign-magnitude, the range is +/- 27-1
For instance, the negative numbers are
1000 0001 (-1)
to
1111 1111 (-127)
The positive numbers are
0000 0001 (+ 1)
to
0111 1111 (+127)

2'S COMPLEMENT REPRESENTATION:


1’s Complement: The 1's complement of a binary number is the number that results when we
complement each bit.

The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's. This is called as
taking complement or 1's complement. Example of 1's Complement is as follows.

18
2's complement: The 2's complement of binary number is obtained by adding 1 to the Least
Significant Bit (LSB) of 1's complement of the number.
2's complement = 1's complement + 1
Example of 2's Complement is as follows.

Positive and Negative Numbers:


The MSB is the sign bit: 0 represents a + sign, and 1 stands for a - sign.

Except for the last entry, the positive and negative numbers are 2's complements of each other.

19
In other words, you can take the 2’s complement of a positive binary number to find the
corresponding negative binary number. For instance:
3  0011
-3  1101
After taking the 2's complement of 0011, we get 1101, which represents -3. The principle also works
in reverse:
-7  1001
+7  0111
After taking the 2’s complement of 1001, we obtain 0111, which represents + 7.
2'S COMPLIMENT ARITHMETIC:
Early computers used sign-magnitude numbers for positive and negative values. This led to
complicated arithmetic circuits
Addition:
1. Represent both operands in signed-2's complement format, i.e., if an operand is non-
negative, keep its original binary form, otherwise represent its magnitude  in 2's
complement:

2. Add operands, discard carry-out of the sign bit MSB (if any).
3. The result is automatically in signed-2's complement form.
There are four possible cases: both numbers positive, a positive number and a smaller negative
number, a negative number and a smaller positive number, and both numbers negative.

Case 1: Both positive.

Case 2: Positive and smaller negative

The 6th bit is automatically dropped.


Case 3: Positive and larger negative

20
The MSB of the result is 1, indicating it is a negative result represented in signed 2's complement
form. Its value can be found by 2's complement to be
Case 4: Both negative.

The 6th bit is automatically dropped. The MSB of the result is 1, indicating it is a negative result
represented in signed 2's complement form. Its value can be found by 2's complement to

be:
Subtraction
The format for subtraction is

There are four cases: both numbers positive, a positive number and a smaller negative number, a
negative number and a smaller positive number, and both numbers negative.
Case 1: Both positive.
Suppose that the numbers are +83 and+ 16. In 2’s complement representation, these numbers appear
as
+83  0101 0011
+16  0001 0000
To subtract+ 16 from +83, the computer will send the + 16 to a 2’s complementer circuit to produce
-16  1111 0000
Then it will add +83 and -16 as follows:

Case 2: Positive and smaller negative. Suppose that the minuend is +68 and the subtrahend is -27. In
2's complement representation, these numbers appear as
+68  01'00 0100
-27  1110 0101
The computer sends -27 to a 2's complementer circuit to produce
+27  0001 1011
Then it adds +68 and +27 as follows:

21
Case 3: Positive and larger negative. Let's use a minuend of+ 14 and a subtrahend of -108. In 2's
complement representation, these numbers appear as
+14 0000 1110
-108 1001 0100
The computer produces the 2’s complement of -108:
+108 0110 1100
Then it adds the numbers like this:

Case 4: Both negative. Assume that the numbers are -43 and - 78. In 2’s complement representation,
the numbers are
-43 1101 0101
-78 1011 0010
First, take the 2’s complement of - 78 to get
+78 0100 1110
Then add to obtain

IMPORTANT DEFINITIONS:
Base: The number of digits or basic symbols in a number system. The decimal system has a base
of 10 because it uses 10 digits. Binary has a base of 2, octal a base of 8, and hexadecimal a base
of 16.
Binary: Refers to a number system with a base of 2, which is, containing two digits.
Bit: An abbreviated fom1 of binary digit. Instead of saying that 10110 have five binary digits,
we can say that it has 5 bits.
Byte: A binary number with 8 bits.
Hexadecimal: Refers to number system with a base of 16. The hexadecimal system has digits 0
through 9, followed by A through F.
Nibble: A binary number with 4 bits.

22
Octal: Refers to a number system with a base of 8, that is, one that uses 8 digits. Normally, these
are 0, 1, 2, 3, 4, 5, 6, and 7.
Parity code: An error detection code using one additional parity bit.
Arithmetic logic unit: A device that can perform both arithmetic and logic function based on
select inputs.
Magnitude: The absolute or unsigned value of a number.
Microprocessor: A digital IC that combines the arithmetic and control sections of a computer.
MSB: Most-significant bit
Parallel addition: A method of binary addition where carry generation at a particular stage does
not depend on availability of carry from previous stage.
Overflow: An unwanted carry that produces an answer outside the valid range of the numbers
being represented.
Ripple carry: Carry that ripples from one stage to other in serial addition.
Serial addition: A method of binary addition where carry sequentially propagates from one
stage to next stage.
Software: A program or programs. The instructions that tell a computer how to process the data.
2's Complement: The binary number that results when 1 is added to the l's complement.

23

You might also like