[go: up one dir, main page]

0% found this document useful (0 votes)
110 views37 pages

Module 01 - Chapter 1

Uploaded by

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

Module 01 - Chapter 1

Uploaded by

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

MODULE 1

NUMBER SYSTEMS AND CODES


NUMBER SYSTEMS
• A system that is used for representing numbers is called
the number system.
• Number system defines a set of values used to represent
quantity.
• There are several types of number systems and the basis of
this classification is the base or radix of the number
system.
• The base or radix of the number system is the total number
of symbols used to denoted the numbers in the number
system.
TYPES OF NUMBER SYSTEMS
• Depending on the base or radix, number systems can be classified
into the following four major types

i. BINARY NUMBER SYSTEM


ii. DECIMAL NUMBER SYSTEM
iii. OCTAL NUMBER SYSTEM
iv. HEXADECIMAL NUMBER SYSTEM
BINARY NUMBER SYSTEM
• A number system with base or radix 2 is called binary number
system.
• The binary number system uses only 2 Digits (0 and 1) to represent
binary numbers.
• All modern digital devices like computers, combinational circuits,
sequential circuits, etc.
• We can convert a binary number into its equivalent decimal number as
follows −
• Let a binary number 1101 and we have to convert it into an equivalent
decimal number, then −
(1×23)+(1×22)+(0×21)+(1×20)
8+4+0+1=13
∴(1101)2=(13)10
DECIMAL NUMBER SYSTEM
• The system of numbers which has base or radix 10, i.e. uses total 10 symbols to
represent numbers of the system is called decimal number system.
• The symbols used in the decimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
where each of these symbols assigned a specific value.
• The decimal number system is a position value system, which means the value of
the digit depends on the position in the number.
• To understand the concept of position value system, consider the following
example.
Let a decimal number 1234 which has total four digits, this number can also be
written as follows −
(1×103)+(2×102)+(3×101)+(4×100)
(1×1000)+(2×1000)+(3×1000)+(4×1)
1000+200+30+4=1234
OCTAL NUMBER SYSTEM
• a number system which has base 8 is called an octal number
system.
• therefore, the octal number system uses 8 digits, (0, 1, 2, 3, 4, 5, 6,
7) to represent the number.
• an octal number can be converted into an equivalent decimal
number as follows −
let an octal number 124 and we need to find its equivalent in
decimal, then
(1×82)+(2×81)+(4×80)
64+16+4=84
∴(124)8=(84)10
HEXADECIMAL NUMBER SYSTEM
• the number system with base or radix 16 is called as hexadecimal number system.
• thus, the hexadecimal number system uses 16 symbol to represent numbers. these
symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. where, a = 10; b = 11; c = 12; d =
13; e = 14; f = 15.
• the hexadecimal number system is extensively used in microprocessors and
microcontrollers.
• we may convert the hexadecimal numbers into decimal numbers. to understand the
conversion process, consider the following example.
let 1af is a hexadecimal number, we can convert it into the equivalent decimal number as
follows −
(1×162)+(A×161)+(F×160)

(1×162)+(10×161)+(15×160)
256+160+15=431
∴(1AF)16=(431)10
BINARY TO DECIMAL CONVERSION
• Binary to decimal conversion is done to convert binary number
system to decimal number system, which means base 2 numeral
system are converted into base 10 numeral system.
• It is important to know binary to decimal conversion because of
computer programming applications. so the machine can understand
only binary number system in form of 0 and 1 whereas humans can
easily understand decimal number system that includes all 10 digits.
• So, it is important to understand how to convert binary number
systems into decimal number systems.
• There are two main methods for converting binary number systems
into decimal number systems. these methods are:
1.Positional notation
2.Doubling
CONVERSION USING POSITIONAL NOTATION
• Write the binary number and count the power of 2 from right to left, starting from 0
onwards.
• Now each binary number has the corresponding power of 2 starting from right to
left. so the most significant bit will have the highest power of 2.
• Add the product of the second step
• The final answer will be converted into a decimal number that is base 10.
Binary Number: (101)2

101
1 x 22 + 0 x 21 + 1 x 20
4+0+1

(5)10 So, the decimal number of (101)2 is (5)10

EG: (10001)2 , (1000.101)2


CONVERSION USING DOUBLING
• Conversion using doubling is one of the simplest ways for converting binary
numbers into decimal numbers.
• We need to take the most signification bit or leftmost digit of the number. then
multiply the digit by 2 and add the second leftmost bit and store the result.
• Similarly, we need to take the result and multiply it by 2 and take the third
leftmost bit and update the result.
• This process will continue till we reach the least significant bit which is the
rightmost bit.
• Binary number: (101)2
=1
=1X2+0=2
=2X2+1=5
SO, THE DECIMAL NUMBER OF (101)2 IS (5)10

• (10011) (10000101)
CONVERSION FROM DECIMAL TO BINARY NUMBER
SYSTEM
• There are various direct or indirect methods to convert a decimal number into
binary number.
• In an indirect method, you need to convert a decimal number into other number
system (e.g., octal or hexadecimal), then you can convert into binary number by
converting each digit into binary number.
• Convert decimal number 125 into binary number.
First convert it into octal or hexadecimal number,
= (125)10
= (1x82+7x81+5x80)10 or
(7x161+13x160)10
Because base of octal and hexadecimal are 8 and 16
respectively.
= (175)8 or (7D)16
Then convert it into binary number by converting each digit.
= (001 111 101)2 or
(0111 1101) = (01111101)
• Here are two direct methods are available for converting a decimal
number into binary number:
i. Performing short division by two with remainder (for integer part)
ii. Performing short multiplication by two with result (for fractional
part)

iii.Performing short division by two with remainder (for integer


part)
• Let decimal number is n then divide this number from 2 because base of binary
number system is 2. note down the value of remainder, which will be either 0 or 1.
• Again divide remaining decimal number till it became 0 and note every remainder
of every step.
• Then write remainders from bottom to up (or in reverse order), which will be
equivalent binary number of given decimal number.
• This is procedure for converting an integer decimal number, algorithm is
given below.
i. Take decimal number as dividend.
ii. Divide this number by 2 (2 is base of binary so divisor here).
iii. Store the remainder in an array (it will be either 0 or 1 because of divisor 2).
iv. Repeat the above two steps until the number is greater than zero.
v. Print the array in reverse order (which will be equivalent binary number of
given decimal number).
Division Remainder (R)

112 / 2 = 56 0
56 / 2 = 28 0
28 / 2 = 14 0
14 / 2 = 7 0
7/2=3 1
3/2=1 1
1/2=0 1
ii. performing short multiplication by two with result (for fractional part)

• Let decimal fractional part is m then multiply this number from 2


because base of binary number system is 2. note down the
value of integer part, which will be either 0 or 1.
• Again multiply remaining decimal fractional number till it
became 0 and note every integer part of result of every step.
• Then write noted results of integer part, which will be equivalent
fraction binary number of given decimal number.
• This is procedure for converting an fractional decimal number, algorithm is
given below.
i. Take decimal number as multiplicand.
ii. Multiple this number by 2 (2 is base of binary so multiplier here).
iii. Store the value of integer part of result in an array (it will be either 0 or 1 because of
multiplier 2).
iv. Repeat the above two steps until the number became zero.
v. Print the array (which will be equivalent fractional binary number of given decimal
fractional number).

• Convert decimal fractional number 0.8125 into binary number.


Multiplication Resultant integer part (R)

0.81252 x 2= 1.625 1

0.6252 x 2= 1.25 1

0.252 x 2= 0.50 0

0.52 x 2= 1.0 1

0x2=0 0
CONVERSION FROM BINARY TO HEXADECIMAL NUMBER
SYSTEM
• POSITIONAL NUMBER SYSTEM
• USING GROUPING

Most Hexa Point Least Significant Bit (LSB)


Significa
nt Bit
(MSB)
162 161 160 16-1 16-2 16-3
256 16 1 1/16 1/256 1/4096

• That means weight of the positions from right to left are as 160, 161,
162, 163and so on. for the integer part
• Weight of the positions from left to right are as 16-1, 16-2, 16-3and so
on. for the fractional part.
• Convert binary number 1101010 into hexadecimal number.
First convert this into decimal number:
= (1101010)2
= 1x26+1x25+0x24+1x23+0x22+1x21+0x20
= 64+32+0+8+0+2+0
= (106)10

Then, convert it into hexadecimal number


= (106)10
= 6x161+10x160
= (6A)16 which is answer.
Using Grouping
• There are only 16 digits (from 0 to 7 and a to f) in hexadecimal
number system, so we can represent any digit of hexadecimal
number system using only 4 bit.
• So, if you make each group of 4 bit of binary input number, then
replace each group of binary number from its equivalent hexadecimal
digits.
• Note that you can add any number of 0’s in leftmost bit (or in most
significant bit) for integer part and add any number of 0’s in rightmost
bit (or in least significant bit) for fraction part for completing the
group of 4 bit, this does not change value of input binary number.
These are following steps to convert a binary number into hexadecimal
number.
• Take binary number
• Divide the binary digits into groups of four (starting from right) for integer part and
start from left for fraction part.
• Convert each group of four binary digits to one hexadecimal digit.
• Convert binary number 1010101101001 into hexadecimal number. since there is no
binary point here and no fractional part. so, = (1010101101001)2
= (1 0101 0110
1001)2
= (0001 0101 0110
1001)2
= (1 5 6 9)16
= (1569)16
Convert binary number 001100101.110111 into hexadecimal number. since there is
binary point here and fractional part. so,

= (001100101.110111)2
= (0 0110 0101 . 1101 1100)2
= (0110 0101 . 1101 1100)2
= (6 5 . D C)16
= (65.DC)16
CONVERSION FROM HEXADECIMAL TO DECIMAL NUMBER
SYSTEM
• There are various indirect or direct methods to convert a hexadecimal number into
decimal number.
• In an indirect method, you need to convert a hexadecimal number into binary or octal
number, then you can convert it into decimal number.
• Convert hexadecimal number f1 into decimal number.
First convert it into binary or octal number,
= (F1)16
= (1111 0001)2 or (011 110 001)2
Because in binary, value of F and 1 are 1111 and 0001 respectively.
Then convert it into decimal number multiplying power of its position of base.
= (1x27+1x26+1x25+1x24+0x23+0x22+0x21+1x20)10 or
(3 6 1)8

= (1x27+1x26+1x25+1x24+0x23+0x22+0x21+1x20)10 or
(3x82+6x81+1x80)10
= (241)10
You can directly convert a hexadecimal number into decimal number
using reverse method of decimal to hexadecimal number.

• Assume any unsigned hexadecimal number is hnh(n-1) ... h1h0.h-1h-2 ...


h(m-1)hm. then the decimal number is equal to the sum of hexadecimal
digits (hn) times their power of 16 (16n), i.e.,
• = hnh(n-1) ... h1h0.h-1h-2 ... h(m-1)hm

• = hnx16n+h(n-1)x16(n-1)+ ... +h1x161+h0x160+h-1x16-1+h-2x16-2+ ... +h(m-


1) x16-(m-1)+h-mx16-m
• This is simple algorithm where you have to multiply positional value of
binary with their digit and get the sum of these steps.
• Convert hexadecimal number ABCDEF into decimal number.
= (ABCDEF)16
= (10x165+11x164+12x163+13x162+14x161+15x160)10

= (10485760+720896+49152+3328+224+15)10
= (11259375)10 which is answer.

• Convert hexadecimal number 1F.01B into decimal number.


= (1F.01B)16
= (1x161+15x160 +0x16-1+1x16-2+11x16-3)10
= (31.0065918)10 which is answer.
ASCII CODE
• The ascii stands for american standard code for information interchange.
• The ascii code is an alphanumeric code used for data communication in digital
computers.
• The ascii is a 7-bit code capable of representing 27 or 128 number of different
characters.
• The ascii code is made up of a three-bit group, which is followed by a four-bit code.
• The ascii code starts from 00h to 7fh. in this, the code from 00h to 1fh is used for
control characters, and the code from 20h to 7fh is used for graphic symbols.
• The 8-bit code holds ascii, which supports 256 symbols where math and graphic
symbols are added.
• The range of the extended ascii is 80h to ffh.
The ascii characters are classified into the following groups:
i. Control Characters
• The non-printable characters used for sending commands to the PC or printer are known as control characters.
• We can set tabs, and line breaks functionality by this code.
• The control characters are based on telex technology. Nowadays, it's not so much popular in use.
• The character from 0 to 31 and 127 comes under control characters.
ii. Special Characters
• All printable characters that are neither numbers nor letters come under the special characters.
• These characters contain technical, punctuation, and mathematical characters with space also. The character from
32 to 47, 58 to 64, 91 to 96, and 123 to 126 comes under this category.
iii. Numbers Characters
• This category of ASCII code contains ten Arabic numerals from 0 to 9.
iv. Letters Characters
• In this category, two groups of letters are contained, i.e., the group of uppercase letters and the group of lowercase
letters. The range from 65 to 90 and 97 to 122 comes under this category.
Excess-3 Code
• The excess-3 code (or xs3) is a non-weighted code used to express code used to
express decimal numbers.
• It is a self-complementary binary coded decimal (bcd) code and numerical system
which has biased representation.
• It is particularly significant for arithmetic operations as it overcomes shortcoming
encountered while using 8421 bcd code to add two decimal digits whose sum
exceeds 9.
• Excess-3 arithmetic uses different algorithm than normal non-biased bcd or binary
positional number system.
Representation Of Excess-3 Code
• Excess-3 codes are unweighted and can be obtained by adding 3 to each
decimal digit then it can be represented by using 4 bit binary number for
each digit.
• An excess-3 equivalent of a given binary binary number is obtained using the
following steps:
i. find the decimal equivalent of the given binary number.
ii. add +3 to each digit of decimal number.
iii. convert the newly obtained decimal number back to binary number to get
required excess-3 equivalent.
• You can add 0011 to each four-bit group in binary coded decimal number
(bcd) to get desired excess-3 equivalent.
These are following excess-3 codes for decimal digits −
Decimal Digit BCD Code Excess-3 Code

0 0000 0011

1 0001 0100

2 0010 0101

3 0011 0110

4 0100 0111

5 0101 1000

6 0110 1001

7 0111 1010

8 1000 1011

9 1001 1100
Convert decimal number 23 to excess-3 code.
• So, according to excess-3 code we need to add 3 to both digit in the
decimal number then convert into 4-bit binary number for result of
each digit. therefore,
• = 23+33=56 =0101 0110 which is required excess-3 code for given
decimal number 23.
Convert decimal number 15.46 into excess-3 code.
• According to excess-3 code we need to add 3 to both digit in the
decimal number then convert into 4-bit binary number for result of
each digit. therefore,
• = 15.46+33.33=48.79 =0100 1000.0111 1001 which is required
excess-3 code for given decimal number 15.46.
GRAY CODE
• The reflected binary code or gray code is an ordering of the
binary numeral system such that two successive values differ in only one
bit (binary digit).
• Gray codes are very useful in the normal sequence of binary numbers
generated by the hardware that may cause an error or ambiguity during the
transition from one number to the next.
• So, the gray code can eliminate this problem easily since only one bit
changes its value during any transition between two numbers.
• Gray code is not weighted that means it does not depends on positional
value of digit.
• This cyclic variable code that means every transition from one value to the
next value involves only one bit change.
• Gray code also known as reflected binary code, because the first (n/2) values
compare with those of the last (n/2) values, but in reverse order.
CONSTRUCTING AN N-BIT GRAY CODE
• n-bit gray code can be generated recursively using reflect and
prefix method which is explained as following below.

i. generate code for n=1: 0 and 1 code.


ii. take previous code in sequence: 0 and 1.
iii. add reversed codes in the following list: 0, 1, 1 and 0.
iv. now add prefix 0 for original previous code and prefix 1 for new
generated code: 00, 01, 11, and 10.
Construct gray code for 3 bit binary numbers:
• Therefore, Gray code 0 and 1 are for Binary number 0 and 1 respectively.
Gray codes: 00. 01, 11, and 10 are for Binary numbers: 00, 01, 10, and
11 respectively.
• Similarly you can construct Gray code for 3 bit binary numbers:
Therefore, Gray Codes Are As Following Below,
For n = 1 bit For n = 2 bit For n = 3 bit

Binary Gray Binary Gray Binary Gray

0 0 00 00 000 000

1 1 01 01 001 001

10 11 010 011

11 10 011 010

100 110

101 111

110 101

111
100
Conversion Of Binary To Gray Code

• Using Exclusive-XOR (⊕) Operation −


• This is very simple method to get gray code from binary number.
these are following steps for n-bit binary numbers −

i. The most significant bit (MSB) of the gray code is always equal
to the MSB of the given binary code.
ii. Other bits of the output gray code can be obtained by xoring
binary code bit at the index and previous index.
• EXAMPLE −convert binary number 111010 into Gray code.

• so, according above algorithm,


• g0=b0⊕b1 = 0⊕1 = 1
• g1=b1⊕b2 = 1⊕0 = 1
• g2=b2⊕b3 = 0⊕1 = 1
• g3=b3⊕b4 = 1⊕1 = 0
• g4=b4⊕b5 = 1⊕1 = 0
• g5=b5 = 1 = 1
• so, gray will be 100111.
Conversion Of Gray Code To Binary

• Using Exclusive-XOR (⊕) Operation −


• This is very simple method to get binary number from gray code.
these are following steps for n-bit binary numbers −

i. The most significant bit (MSB) of the binary code is always equal
to the MSB of the given binary number.
ii. Other bits of the output binary code can be obtained by
checking gray code bit at that index. if current gray code bit is
0, then copy previous binary code bit, else copy invert of
previous binary code bit.
• EXAMPLE − convert Gray code 100111 into binary number.
• so, according above algorithm,
• b5=g5=1=1

• b4=g5⊕g4 =1⊕0 =1

• b3=b4⊕g3 =1⊕0 =1

• b2=b3⊕g2 =1⊕1 =0

• b1=b2⊕g1 =0⊕1 =1

• b0=b1⊕g0 =1⊕1 =0
• so, binary number will be 111010.

You might also like