0% found this document useful (0 votes)
12 views

Number System

Number system

Uploaded by

shreyas19052006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Number System

Number system

Uploaded by

shreyas19052006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

NUMBER SYSTEM

Introduction
In digital computers, data and instructions are stored in the computer’s memory using binary code
(or machine code) represented by Binary dig IT 's 1 and 0 called BITs. The data may contain
digits, alphabets or special character, which are then converted to bits, understandable by the
computer. All arithmetic operations are performed using binary bits. The study of different number
systems is necessaryto understand data representation.
The number system uses well defined symbols called digits. The values of digits depend on the
position in which they appear in the number.
Number systems are basically classified into two types. They are,
1. Non-positional number system.
2. Positional number system.

Non-positional number system


In olden days people made use of this type of number system for simple calculations like additions
and subtractions. The non-positional number system consists of different symbols that are used to represent
numbers.
Roman number system is an example of the non-positional number system i.e. I=1, V=5, X=10,
L=50. Each of these symbols represents a value, irrespective of the positions. This number system
cannot be used effectively to perform arithmetic operations.

Positional number system


Decimal, Binary, Octal and Hexadecimal number systems are some of the examples of this type of
number systems.
The base or radix of a number system is the total number of digits present in that system.
Every number is represented by a base (or radix) x, which represents x digits. To determine the
quantity that the number represents, the number is multiplied by an integer power of x depending on the
position it is located and then finds the sum of the weighted digits.
The base or radix of a number system is the total number of digits present in any number system.
Decimal number system
This is the most commonly used number system in our daily life. It has 10 numbers from 0 to 9; hence
its radix is 10. The positional values are expressed in powers of 10.
Example 3.1 Consider a decimal number 542.76(10) which can be represented in equivalent value as:
5x102 + 4x101 + 2x100 + 7x10-1 + 6x10-2
Table 3.1 shows the weightage of the positional values of the decimal number:

Hundreds Tens Units One-tenth One-hundredth


Weights 102 101 100 10-1 10-2
Digits 5 4 2 7 6
Values 500 40 2 0.7 0.06

Binary number system


The digital computers cannot process decimal numbers, hence it has to be converted to binary
digits 0 (low voltage) and 1 (high voltage), which is suitable to represent the bi-stable of electronic
components.
The representation of data in a computer is usually in binary digits 0 and 1. Hence the base is 2.
The positional values are expressed in powers of 2. It is very essential to know how to count a binary
number and also the conversion from binary to all other number systems.
E x a m p l e 3 . 2 C o n s i d e r a b i n a r y n u m b e r 1 1 0 1 1 . 1 0 1

(2)
which can be represented in equivalent
values:
1x24 + 1x23 + 0x22 + 1x21 + 1x20+1x2-1 + 0x2-2 + 1x2-3

Table 3.2 shows the weightage of the positional values of the binary number:

Weights 24 23 22 21 20 2-1 2-2 2-3


Bits 1 1 0 1 1 1 0 1
Values 16 8 4 2 1 0.5 0.25 0.125

In the binary number 11010(2) the left most bit 1 is the highest order bit. It is called as the most
significant bit (MSB). Rightmost bit 0 is the lower order bit. It is called least significant bit (LSB).

Octal number system


Binary number representation generates long sequence of 1’s and 0’s, while representing
large decimal numbers. To overcome this problem, other number systems like octal and hexadecimal
number system is used which can effectively compress long strings of binary numbers.
The octal number system has 8 digits 0, 1, 2, 3, 4, 5, 6 and 7. Its radix is 8. The positional values
are expressed in powers of 8.
Example 3.3 Consider an octal number 234.56(8) which can be represented in equivalent value as:
2x82 + 3x81 + 4x80 + 5x8-1 + 6x8-2

The table 3.3 shows the weightage of the positional values of the octal number:

Weights 82 81 80 8-1 8-2


Digits 2 3 4 5 6
Values 64 8 1 0.125 0.03125

Hexadecimal number system


This number system has 16 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. The radix is 16.
The positional values are expressed in powers of 16. The digits A, B, C, D, E and F have the decimal
equivalents 10, 11, 12, 13, 14 and 15 respectively.
Example 3.4 Consider a hexadecimal number 5AF.D(16) which can be represented in equivalent
value as:
5x162 + Ax161 + Fx160 + Dx16-1

The table 3.6 shows the weightage of the positional values of the hexadecimal number:

Weights 162 161 160 16-1


Digits 5 A F D
Values 256 16 1 0.0625

Number system conversions (All types)


In representing the data on computers we need to convert the data from one number system to
other number system. In this section we study the inter conversions of number systems.

Decimal to binary conversion:


Step1: Divide the given decimal number by 2
Step2: Note the quotient and remainder.
Step2: Repeat the step1 and step2 until the quotient becomes zero.
Step3: The first remainder will be the LSB and the last remainder is the MSB. The
equivalent binary number is then written from left to right i.e., from MSB to LSB.
Example 3.5 Consider the decimal number 53(10) which can be represented in binary as:

Therefore, 53(10) = 110101(2)

Decimal fraction to binary conversion:


Step 1: Multiply the decimal fraction by 2, note the carry and the product.
Step 2: Repeat Step1until the fractional product becomes zero.
Step 3: The first carry will be the MSB and the last carry is the LSB. The equivalent binary fraction
is then written from MSB to LSB ( right to left).

Example 3.6 Consider the decimal fraction 0.3125(10)

Multiply by 2 Carry Product


0.3125 x 2 0 (MSB) 0.625
0.625 x2 1 0.25
0.25 x 2 0 0.50
0.50 x2 1 (LSB) 0.00
0.00
Therefore, 0.3125(10) = 0.0101(2)

Binary to decimal conversion


Step1: Multiply each bit of the binary number by its positional weight.
Step2: Add all the products.

Example 3.7 Consider the binary number 11011.101(2) which can be represented in decimal value
as:
1x24 +1x23+ 0x22 + 1x21 + 1x20 + 1x2-1 + 0 x 2-2 + 1x2-3
The table 3.2 shows the weightage of the positional values of the binary number.

Weights 24 23 22 21 20 2-1 2-2 2-3


Bits 1 1 0 1 1 1 0 1
Values 16 8 4 2 1 0.5 0.25 0.125

Therefore, 11011.101(2) = 27.625(10)

Decimal to octal conversion


Step 1: Divide the given decimal number by 8
Step 2: Note the quotient and remainder.
Step 3: Repeat the step1 and step 2 until the quotient becomes zero.
Step 4: The first remainder will be the LSB and the last remainder is the MSB. The
Equivalent octal number is then written from left to right i.e. from MSB to LSB.

Example 3.8 Consider the decimal number 459(10)

Therefore, 459(10) = 713(8)

Octal to decimal conversion


Step 1: Multiply each digit of an octal number by its weight.
Step 2: Add all the products.

Example 3.9 Consider an octal number 234.56(8) which can be represented in decimal value as:
2x82 + 3x81 + 4x80 + 5x8-1 + 6x8-2

Table 3.3 below shows the weightage of the positional values of the octal number:

Weights 82 81 80 8-1 8-2


Digits 2 3 4 5 6
Values 64 8 1 0.125 0.03125
Table 3.3
Therefore, 234.56(8) = 156.71875(10)
Decimal to hexadecimal conversion
Step 1: Divide the given decimal number by 16.
Step 2: Note the quotient and remainder.
Step 3: Repeat step1and step2 until the quotient is becomes zero.
Step 4: The first remainder is the LSB and the last remainder is the MSB. The hexadecimal
number is written from left to right with MSB occurring first.

Example 3.10 Consider a decimal number 559(10)

Therefore, 559(10)= 22F (16)

Hexadecimal to decimal conversion


Step1: Multiply each digit of the hexadecimal number by its positional weight.
Step2: Add all the products.

Example 3.11 Consider a hexadecimal number 5AF.D (16) which can be represented in decimal
value as:
5x162 + A x 161 + F x 160 + D x 16-1

Table 3.6 shows the weightage of the positional values of the hexadecimal number:

Weights 162 161 160 16-1


Digits 5 A F D
Values 256 16 1 0.0625

Therefore, 5AF.D (16) = 1455.8125(10)

Binary to octal conversion


In the given binary number, the binary digits are grouped into groups of three bits starting from the
binary point and convert each group into its equivalent octal number. For whole numbers, it may be
necessary to add a zero as the MSB. Similarly, when representing fractions, it may be necessary to add a
trailing zero in the LSB to complete grouping of three bits.
Adding a leading 0 as the MSB into the whole number and adding a 0 trailing 0 as the LSB into the
fractional binary number does not change the value of the number.

Therefore, 0.110111(2) = 0.67(8)

Octal to binary conversion


The application of octal numbers is to represent binary numbers, as it is easier to read large numbers
in octal form than in binary form. Each octal digit is represented by a three-bit binary number as in table
Hence it is very easy to convert from octal to binary.

Octal digit Binary digit


0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Table 3.4

Consider the octal number 456(8)


4 100
5 101
6 110
Therefore, 456(8) =100101110(2)
Consider the octal number 73.16(8)
7 111
3 011
1 001
6 110
Therefore, 73.16(8) = 111011.001110(2)

Binary to Hexadecimal conversion


The binary bits are grouped into four bits starting from the binary point and replace each group
by a hexadecimal digit. For whole numbers, it may be required to add a zero as the MSB to complete a
group of four bits. Similarly, when representing fractions, it may be required to add a trailing zero as
the LSB to complete a group of four bits. This addition of zeros will not change the value of the
binary number.

shows each hexadecimal number may be represented as a 4-digit number.

Decimal Binary Hexadecimal


0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Hexadecimal to binary conversion
Each digit of a hexadecimal number is replaced by a 4-bit binary number (Refer table 3.5).
Example 3.18 Consider a hexadecimal number CEBA(16)
C 12 1100
E 14 1110
B 11 1011
A 10 1010
Therefore, CEBA (16)=1100 1110 1011 1010(2)

Octal to Hexadecimal conversion


Using binary system, we can easily convert octal numbers to hexadecimal numbers and vice-versa.
Step 1: Write the binary equivalent of each octal digit.
Step 2: Regroup them into 4 bits from the right side with zeroes added, if necessary.
Step 3: Convert each group into its equivalent hexadecimal digit.

Example 3.19 Consider an octal number 274(8)


2 010
7 111
4 100
Therefore, 274(8) =010 111 100(2)
Group the bits into groups of 4-bits as 0 1011 1100

Hexadecimal to octal conversion


Step 1: Write the binary equivalent of each hexadecimal digit.
Step 2: Regroup them into 3-bits from the right side with zeros added, if necessary.
Step 3: Convert each group into octal equivalent.

Example 3.20 Consider a hexadecimal number FADE (16)


F 15 1111
A 10 1010
D 13 1101
E 14 1110

Therefore, FADE (16) = 1111 1010 1101 1110(2)

001 111 101 011 011 110

1 7 5 3 3 6

Therefore, FADE (16)= 175336(8)

Representation of signed integers


The digital computers handle both positive and negative integers. So some means is required for
representing the sign of the number (+ or -). This is done by adding the leftmost bit to the number called
the sign bit. Apositive number has a sign bit 0, while the negative has a sign bit 1. Hence it is also called as
fixed point representation.
A negative signed integer can be represented in one of the following ways
 Sign and magnitude representation
 One’s complement representation
 Two’s complement representation

Sign and magnitude representation


An integer containing a sign bit followed by magnitude bits are called sign-magnitude integer. The
MSB is always the sign bit and the remaining bits always stand for magnitude.
Example 3.21 If in a Computer of word size of 1 byte (8 bits), then an integer +83 and -83 is
represented in 8-bit sign-magnitude representation as

27 = 128 numbers can be represented using 7 bits, numbers from 0 to +127 and 0 to -128.

1’s complement representation


This is the simple method of representing negative binary numbers. The negative binary number is
formed by subtracting the value of each bit in the word from 1. This changes the value of each bit from 0
to 1 and 1 to 0.
Example 3.22 Consider the binary number 101000.
1’s complement of this number is obtained as follows:
111111
- 101000
010111
Thus, one’s complement of 101000 is 010111.
We observe that one’s complement of a binary number is easily obtained by changing all 1’s into 0’s
and all 0’s into 1’s of the binary number.

2’s complement representation


The 2’s complement of a binary number is obtained by adding 1 to the 1’s complement of the binary
number.
Two’s complement of a binary number = One’s complement + 1
Example Consider the binary number 101000. 2’s complement of this number is obtained as
follows:
One’s complement of 101000 = One’s complement of 101000 + 1
= 010111 + 1
= 011000
Thus, 011000 is the 2’s complement of 101000.
Example

All modern computers operate based on 2’s complement representation because of its hardware
being simpler which makes the computer work faster.

Binary arithmetic
It involves addition, subtraction, multiplication and division operations which are fundamental to all
digital computers. Binary addition is the most important operation because it can be used to perform other
arithmetic operations.

Binary addition
The basic rules of binary addition are given in table 3.7:
Addend1 Addend2 Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

The above table adds only two bits and gives sum and carry. If a carry is generated, it should be
carried over to the addition of next two bits. Thus the addition is a 3-bit addition.
gives the rules to add two addend bits and a carry generated from the addition of previous
bits.
Addend1 Addend2 Previous carry Sum Carry
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 Add 75 and 18 in binary


75 = 64 + 8 + 2 + 1 = 1001011
18 = 16 + 2 = 10010

Carry 1
Addend 1 1001011
Addend 2 10010
Sum 1011101

Binary Subtraction

It is performed as the addition of negative binary numbers.


For example, 8-5 may be performed as 8+ (-5).
The basic rules for binary subtraction are given in table 3.8.

Minuend Subtrahend Difference Borrow


0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0

When we subtract a 1 from a 0, it is necessary to borrow 1 from the next left column i.e. from the
next higher order position.
Simple subtraction

Example 3.27 Add 75 and -25.

75 = 64 + 8 + 2 +1 = 1001011
25 = 16 + 8 + 1 = 11001

Borrow
Minuend 1001011
Subtrahend 11001

Difference 110010

Subtraction using 1’s complement


Though subtraction using borrow is straight, the computer does not use this method due to
circuit complications. It does subtraction using complement methods.

Case1: Subtracting a smaller number from a larger number (minuend is greater than subtrahend)
Step 1: Find the 1’s complement of the subtrahend.
Step 2: Add this to the minuend.
Step 3: Carry is generated. This carry is called as the end around carry.
Step 4: Add the end around carry back to the LSB to get the final difference.
Example 3.28 Subtract 15 from 23 using 1’s compliment
Minuend 23 10111
Subtrahend -15 - 01111
? ?

Minuend 10111
1’s compliment of Subtrahend +10000
End around carry 100111
Add end carry to LSB + 1
Difference 1000
Case 2: Subtracting a larger number from a smaller number (minuend is less than subtrahend).
Step 1: Find the 1’s complement of the subtrahend.
Step 2: Add this to the minuend.
Step 3: There will be no carry. Re-complement the answer to get the difference.
Step 4: Add the end around carry back to the LSB to get the final difference.

Example 3.29 Subtract 52 from 25 using 1’s compliment.


Minuend 25 011001
Subtrahend -52 - 110100
? ?

Minuend 011001
1’s compliment of Subtrahend + 001011
100100
There is no carry. Therefore re-complement and insert a negative sign, we get - 011011

Subtraction using 2’s complements


Case 1: Subtracting a smaller number from a larger number (minuend is greater than subtrahend).
Step 1: Find the 2’s complement of the subtrahend.
Step 2: Add it to the minuend.
Step 3: Carry is generated. Discard the carry and the remaining bits give the difference.

Example 3.30 Subtract 9 from 17 using 2’s complement.


Minuend 17 10001
Subtrahend -9 -01001
? ?
2’s complement of 01001 = 1’s complement of 01001 + 1
= 10110 + 1
= 10111
Minuend 10001
2’s complement of Subtrahend +10111
101000
Carry is generated. Discarding the carry, we get 1000 = 8.
Step 1: Find the 2’s complement subtrahend.
Step 2: Add it to the minuend.
Step 3: There is no carry. Hence take the 2’s complement of the answer and place a negative sign in
front.

Example Subtract 47 from 26 using 2’s complement


Minuend 26 011010
Subtrahend - 47 - 101111
? ?
2’s complement of 101111 = 1’s complement of 101111 + 1
= 010000 + 1
= 010001
Minuend 011010
2’s complement of Subtrahend + 010001
101011
2’s complement of the answer = -10101 = -21

Computer codes
Computer codes are used for internal representation of data in computers. As computers use binary
numbers for internal data representation, computer codes use binary coding schemes. In binary coding,
every symbol that appears in the data is represented by a group of bits. Thus computer codes represent
various characters, numbers and control keys that the computer user selects on the keyboard. Some of
the commonly used computer codes are:
 Binary coded decimal (BCD)
 Extended binary coded decimal interchange code (EBCDIC)
 American standard code for information interchange (ASCII)
 Excess-3 code

Introduction to BCD, EBCDIC, ASCII, Excess-3 Codes


One way of encoding decimal numbers digit by digit using group of 4 bits is called BCD code. Two
popular 4-bit BCD codes are

i. BCD code (or Weighted BCD code or 8421 code)


BCD stands for Binary Coded Decimal. It is one of the early computer codes. In this coding system,
the bits are given from left to right, the weights 8, 4, 2, 1 respectively. Since these weights are just the
place values in the binary system, a decimal digit is encoded as its binary representation.
Example 3.32 The decimal number 537 is represented in 4-bit 8421 BCD code as
5 3 7

0101 0011 0111


In 4-bit BCD code only 24 =16 configurations are possible which is insufficient to represent the
various characters used by computers. Hence 6-bit BCD code was developed by adding two zone
positions with which it is possible to represent 26 = 64 characters.
BCD code BCD code
Character Character
Zone Digit Zone Digit
A 01 0 0 0 1 J 10 0 0 0 1
B 01 0 0 1 0 K 10 0 0 1 0
C 01 0 0 1 1 L 10 0 0 1 1
D 01 0 1 0 0 M 10 0 1 0 0
E 01 0 1 0 1 N 10 0 1 0 1
F 01 0 1 1 0 O 10 0 1 1 0
G 01 0 1 1 1 P 10 0 1 1 1
H 01 1 0 0 0 Q 10 1 0 0 0
I 01 1 0 0 1 R 10 1 0 0 1

BCD code BCD code


Character Character
Zone Digit Zone Digit
S 11 0 0 0 1 1 00 0 0 0 1
T 11 0 0 1 0 2 00 0 0 1 0
U 11 0 0 1 1 3 00 0 0 1 1
V 11 0 1 0 0 4 00 0 1 0 0
W 11 0 1 0 1 5 00 0 1 0 1
X 11 0 1 1 0 6 00 0 1 1 0
Y 11 0 1 1 1 7 00 0 1 1 1
Z 11 1 0 0 0 8 00 1 0 0 0
9 00 1 0 0 1
0 00 1 0 1 0

i. Excess-3 BCD Code or XS-3 Code


The excess–3 BCD code is a non-weighted code and is obtained from 8421 BCD code by
adding 3 (0011).

Example 3.33: The decimal number 537 would be represented in the XS-3 code as

5 3 7  Decimal digit
0101 0011 0111  8421 BCD Code
0011 0011 0011  Add 3 (0011)
1000 1010 0110  XS-3 Code
There are 8 bit BCD systems. They are EBCDIC and ASCII.

iii. EBCDIC code - EBCDIC stands for Extended Binary Coded Decimal Interchange Code
This coding was developed by IBM. It is an 8 bit code and so it has 28 = 256 possible code groups
This coding scheme is used with large computers as mainframes.

EBCDIC code EBCDIC code


Character Character
Zone Digit Zone Digit
A 1100 0 0 0 1 J 1101 0 0 0 1
B 1100 0 0 1 0 K 1101 0 0 1 0
C 1100 0 0 1 1 L 1101 0 0 1 1
D 1100 0 1 0 0 M 1101 0 1 0 0
E 1100 0 1 0 1 N 1101 0 1 0 1
F 1100 0 1 1 0 O 1101 0 1 1 0
G 1100 0 1 1 1 P 1101 0 1 1 1
H 1100 1 0 0 0 Q 1101 1 0 0 0
I 1100 1 0 0 1 R 1101 1 0 0 1

EBCDIC code EBCDIC code


Character Character
Zone Digit Zone Digit
S 1110 0 0 0 1 01 1111 0 0 0 1
T 1110 0 0 1 0 02 1111 0 0 1 0
U 1110 0 0 1 1 03 1111 0 0 1 1
V 1110 0 1 0 0 04 1111 0 1 0 0
W 1110 0 1 0 1 05 1111 0 1 0 1
X 1110 0 1 1 0 06 1111 0 1 1 0
Y 1110 0 1 1 1 07 1111 0 1 1 1
Z 1110 1 0 0 0 08 1111 1 0 0 0
09 1111 1 0 0 1
i. ASCII code - ASCII stands for American Standard Code for Information Interchange
It is a 7 bit code, which is possible to represent 27 = 128 characters. The first 3 bits are used
as zone bits and the last 4 bits indicate the digit. This coding is used to represent alphanumeric and
some special characters. It is used in micro computers for data communications. Since microcomputers
use 8-bits the ASCII was extended to an 8 bit code.

ASCII Table and Description


Computers can only understand numbers, so an ASCII code is the numerical representation of a
character such as ‘a’ or ‘@’ or an action of some sort. ASCII was developed a long time ago and now the
non-printing characters are rarely used for their original purpose. Below is the ASCII character table and
this includes descriptions of the first 32 non-printing characters. ASCII was actually designed for use with
Teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however
in ASCII format, all this means is theywant ‘plain’ text with no formatting such as tabs, bold or
underscoring the raw format that any computer can understand. This is usually so they can easily import
the file into their own applications without issues. Notepad.exe creates ASCII text, or in MS Word you
can save a file as‘text only’.

You might also like