Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Module 3

The document discusses different number systems including hexadecimal, octal, and their conversions. Hexadecimal uses base 16 with digits 0-9 and A-F. It can compactly represent 4-bit binary values. Octal uses base 8 with digits 0-7. Conversions between number systems involve grouping binary digits and replacing with digits from the target base.

Uploaded by

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

Module 3

The document discusses different number systems including hexadecimal, octal, and their conversions. Hexadecimal uses base 16 with digits 0-9 and A-F. It can compactly represent 4-bit binary values. Octal uses base 8 with digits 0-7. Conversions between number systems involve grouping binary digits and replacing with digits from the target base.

Uploaded by

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

4.

Hexadecimal Number System


4. Hexadecimal Number System
 Hexadecimal Number System is one the type of Number
Representation techniques, in which there value of base is 16.
 There are only 16 symbols or possible digit values
 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
 Where A, B, C, D, E and F are single bit representations of decimal value 10, 11,
12, 13, 14 and 15 respectively.
 It requires only 4 bits to represent value of any digit.

 Representing Binary in compact form


 1101100000110 = 1B06 in Hexa
2
Counting in Hexadecimal

Decimal Binary Hexadecimal Decimal Binary Hexadecimal

0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
Counting in Hexadecimal

Decimal Hexa- Decimal Hexa- Decimal Hexa-


Decimal Decimal Decimal
16 10 24 18 32 20
17 11 25 19 33 21
18 12 26 1A 34 22
19 13 27 1B 35 23
20 14 28 1C 36 24
21 15 29 1D 37 25
22 16 30 1E 38 26
23 17 31 1F 39 27
Binary to Hexadecimal Conversion
Binary to Hexadecimal Conversion
 Conversion from binary to hexadecimal (and conversely) can be
done by inspection because each hexadecimal digit
corresponds to exactly four binary digits (bits).
 Starting at the binary point, the bits are divided into groups of
four, and each group is replaced by a hexadecimal digit:

 Example:
 11010110101110010110

 1101 0110 1011 1001 0110

 D 6 B 9 6
Binary to Hexadecimal Conversion
 Example:
 As shown in Equation , extra 0’s are added at each end of

the bit string as needed to fill out the groups of four bits.

 Example:
Hexadecimal to Binary Conversion
Hexadecimal to Binary Conversion
 Conversion from hexadecimal to binary is done by reversing the preceding
procedure.
 Each hexadecimal digit is converted to its four-digit binary equivalent.

 The procedure is illustrated in the following examples:

 FD13
 1111 1101 0001 0011
Hexadecimal to Binary Conversion

11
Decimal to Hexadecimal Conversion
Decimal to Hexadecimal Conversion
 Repeated Division by 16
 Step 1: First, divide the decimal number by 16, considering the number as an integer.
 Step 2: Keep aside the remainder.
 Step 3: Again divide the quotient by 16 and repeat till you get the quotient value equal
to zero.
 Step 4: Now take the values of the remainder’s left in the reverse order to get the
hexadecimal numbers
Decimal to Hexadecimal Conversion
Decimal to Hexadecimal Conversion

Number Quotient Remainder

2096 131 0

131 8 3

8 0 8
Decimal to Hexadecimal Conversion
Decimal to Hexadecimal Conversion
Hexadecimal to Decimal Conversion
Hexadecimal to Decimal Conversion

 Sum-of-Weights
 Example: Convert CA02 to Decimal using Sum of
Weights technique
 Solution:
CA02
= (C x 163) + (A x 162) + (0 x 161) + (2 x 160)
= (12 x 163) + (10 x 162) + (0 x 161) + (2 x 160)
= (12 x 4096) + (10 x 256) + (0 x 16) + (2 x 1)
= 49152 + 2560 + 0 + 2
= 51714
5. Octal Number System
5. Octal Number System
 It is a base‐8 system

 It has eight digits: 0, 1, 2, 3, 4, 5, 6, 7.

 An example of an octal number is 127.4

 Representing Binary in compact form


 1101100000110 = 15406
2 8

 Not commonly used in the presence of Hexadecimal Number


System

 Octal digit represented by a 3-bit binary


5. Octal Number System

 To determine its equivalent decimal value, we


expand the number in a power series with a base
of 8:

22
Table shows the decimal and binary equivalents of the Octal
digits 0 to 7

Decimal Binary Octal


0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
Counting in Octal

Decimal Octal Decimal Octal Decimal Octal


8 10 16 20 24 30
9 11 17 21 25 31
10 12 18 22 26 32
11 13 19 23 27 33
12 14 20 24 28 34
13 15 21 25 29 35
14 16 22 26 30 36
15 17 23 27 31 37
Binary to Octal Conversion
Binary to Octal Conversion
• Example
• Consider the 21-bit binary string which is to be converted into Octal
• The 21-bit binary string is divided into groups of 3-bits starting from
the least significant bit
• 7 groups of 3-bits are formed.
• In the next step each group of 3-bits is replaced by the equivalent
Octal digit.
• The result is a 7-digit Octal Number.

 011010110101110010110
 011 010 110 101 110 010 110
 3 2 6 5 6 2 6
Binary to Octal Conversion
• Example:

• Consider the 13-bit binary string which is to be converted into Octal


• The 13-bit binary string is divided into groups of 3-bits starting from the least
significant bit
• 4 groups of 3-bits are formed and an incomplete 5th group with a single bit.
• Two most significant zero bits are appended to complete the group.
• Each 3-bit group is replaced by the equivalent Octal digit to complete the
conversion

 1011011101001
 1 011 011 101 001
 001 011 011 101 001
 1 3 3 5 1
Octal to Binary Conversion
Octal to Binary Conversion
• Example:
• Consider the 4 digit Octal number which is to be converted into Binary
• Each Octal digit is replaced by its equivalent 3-bit binary number.
• Thus Octal 1 is replaced by 001
• Octal 7 is replaced by 111
• Octal 2 is replaced by 010
• And Octal 6 is replaced by 110

 1726
 001 111 010 110
Decimal-Octal Conversion
Decimal-Octal Conversion
• Repeated Division by 8
• Example:
• Consider the Repeated division by 8 method to convert Decimal 2079 into Octal
• The decimal number 2079 is divided by 8 which results in a quotient value of 259 and the remainder
7 Number Quotient Remainder
• The remainder 7 is noted and the quotient 259 is divided by 8.
• 259 divided by 8 results in a quotient value of 32 and a remainder value of 3. 2079 259 7
The remainder 3 is noted and the quotient 32 is divided by 8.
(a0)

• 32 divided by 8 results in a quotient value of 4 and a remainder 0.


• The remainder 0 is noted and the quotient value 4 is divided by 8.
• This results in a quotient value of 0 which indicates the completion of the repeated division by 8 259 32 3

method.
The remainder 4 and the three remainders noted earlier represent the 4 digit Octal Number 4037
(a1)
32 4 0
(a2)
4 0 4
(a3)
Octal to Decimal Conversion
Octal-Decimal Conversion
 Sum-of-Weights

 Example:
• Consider the Sum-of-Weights 4037
method to convert Octal 4037 to
Decimal =(4 x 83) + (0 x 82) + (3 x 81) + (7 x 80)
• An expression in terms of the base =(4 x 512) + (0 x 64) + (3 x 8) + (7 x 1)
number 8 and weights is written =2048 + 0 + 24 + 7
• The expression is solved to give four =2079
sum terms 2048, 0, 24 and 7
• The four terms are added to result in
the number 2079 the decimal
equivalent of Octal 4037
Alternate Representations

• There are many different ways to represent binary


numbers, other than the representation that we have
discussed.
• Many of these alternate representations are used to
support specific applications and requirements.

• BCD Code (Binary Coded Decimal Code)


• Gray Code
BCD (Binary Coded Decimal) Code

35
BCD (Binary Coded Decimal) Code

 Although most large computers work internally with binary


numbers, the input output equipment generally uses decimal
numbers. Because most logic circuits only accept two-valued
signals, the decimal numbers must be coded in terms of
binary signals.

 In the simplest form of binary code, each decimal digit is


replaced by its binary equivalent

36
BCD (Binary Coded Decimal) Code
• Most digital systems display a count value or the
time in decimal on 7-segment LED display panels.

• Since the numbers displayed are in decimal,


therefore the binary code used to display the
decimal numbers is designed to represent a
single digit.

• Consider a 2-digit 7-segment display that can


display a count value from 0 to 99. To display the
two decimal digits two separate binary codes are
applied at the 7-segment display circuit inputs.
Since each binary code has to specify a digit
between 0 and 9 therefore only 10 different binary
codes are required.
BCD (Binary Coded Decimal) Code
 For 0 to 9 decimal numbers both binary and BCD is equal but when
decimal number is more than one bit BCD differs from binary

 Consider decimal185 and its corresponding value in BCD and binary:

 Binary Code to represent decimal digits 0-9

 Used by Decimal Number Displays


BCD (Binary Coded Decimal) Code
• How many binary bits are required to represent 10
unique codes?
• A 4-bit binary code allows 16 different binary combinations to be
represented. Only the first 10, 4-bit binary codes are used, the remaining
6 codes are not used.

• Thus displaying a 2-digit decimal number 79 would require the digital


system to generate two BCD numbers 0111 and 1001 respectively
BCD (Binary Coded Decimal) Code
• The Table shows the valid
BCD codes.

Decimal BCD Decimal BCD


• A 4-bit binary code can
represent up to 16
different values.
0 0000 5 0101
• The 4-bit BCD code 1 0001 6 0110
represents decimal digits
0 to 9 in binary. Thus the 2 0010 7 0111
binary code 1010, 1011, 3 0011 8 1000
1100, 1101, 1110 and 1111
are considered to be 4 0100 9 1001
invalid BCD codes.
BCD Addition
• Example:

• Consider the addition of two, 2-digit BCD numbers 23 and 45


• BCD numbers are added using Binary addition method, resulting in 68

• Consider the addition of two, 2-digit BCD numbers 23 and 49


• Adding least significant digits 3 and 9 results in 12 represented as 1100.
• 1100 is an invalid BCD digit.
• Secondly adding 3 and 9 in decimal should result in 2 as the sum and 1 as the carry.
• The BCD result 0110 1100 is equivalent to 62 which is incorrect as the carry generated
by the addition of the least significant digits has not been considered.

41
BCD Addition

23 0010 0011
45 0100 0101
68 0110 1000

23 0010 0011
49 0100 1001
72 0110 1100
 1100 is illegal BCD number
 Note:
 This means that although 16 numbers (24) can be represented using four binary
digits, in the BCD numbering system the six binary code combinations of: 1010
(decimal 10), 1011 (decimal 11), 1100 (decimal 12), 1101 (decimal 13), 1110
(decimal 14), and 1111 (decimal 15) are classed as forbidden numbers and can
not be used
BCD Addition
 Add a 0110 (6) to an invalid BCD
number
 Carry added to the most significant BCD
digit • When addition of BCD
digits results in an invalid
BCD number or a
23 0010 0011 carry.The number 0110 (6
decimal) is added to the
49 0100 1001 result.
• Reconsidering the
72 0110 1100 addition of BCD 23 and
49. The addition of digits
0110 3 and 9 results in 1100 an
0111 0010 invalid BCD number
• A 0110 decimal 6 is
added which results in
0010 and a carry which is
added to 0110 to result in
 Why So ?????

44
BCD Addition
 Example:
Gray Code

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).

 A Gray code has the property that the codes for successive decimal
digits differ in exactly one bit. For example, the codes for 6 and 7
differ only in the fourth bit, and the codes for 9 and 0 differ only in
the first bit.

 A Gray code is often used when translating an analog quantity, such


as a shaft position, into digital form.
 In this case, a small change in the analog quantity will change only one bit in the code,
which gives more reliable operation than if two or more bits changed at a time.

47
Gray Code

 Is Gray code a weighted code?


 It is the non-weighted code that implies there are no
specific weights allocated to the bit position. It has a
very unique feature that only one bit will alter each
time the decimal number is incremented
 In general, the decimal value of a coded digit cannot be
computed by a simple formula when a non-weighted
code is used

48
Gray Code
 The output data of many physical systems are quantities that are
continuous. These data must be converted into digital form before they are
applied to a digital system.

 Continuous or analog information is converted into digital form by means of


an analog‐to‐digital converter.

 It is sometimes convenient to use the Gray code shown to represent digital


data that have been converted from analog data.

 The advantage of the Gray code over the straight binary number
sequence is that only one bit in the code group changes in going from
one number to the next.

49
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.

• Generate code for n=1: 0 and 1 code.

• Take previous code in sequence: 0 and 1.

• Add reversed codes in the following list: 0, 1, 1


and 0.

• Now add prefix 0 for original previous code


and prefix 1 for new generated code: 00, 01,
11, and 10
• 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:
50
Gray Code

• Consider the 3-bit binary Decimal Gray Binary


code and the 3-bit Gray
code representing the 0 000 000
decimal numbers 0 to 7.
1 001 001
• The binary code is a
positional code and the 2 011 010
three bits starting from the
least significant bit have the
3 010 011
weights 1,2 and 4. 4 110 100
• The Gray Code is not a 5 111 101
positional code.
6 101 110
• However, the change from
one value to the next using 7 100 111
the Gray code guarantees a
single bit change.
Gray Code
 The Gray code is used in applications in which the normal sequence of
binary numbers generated by the hardware may produce an error or
ambiguity during the transition from one number to the next.

 If binary numbers are used, a change, for example, from 0111 to 1000 may
produce an intermediate erroneous number 1001 if the value of the
rightmost bit takes longer to change than do the values of the other three
bits. This could have serious consequences for the machine using the
information.

 The Gray code eliminates this problem, since only one bit changes its
value during any transition between two numbers
Alphanumeric Code
Alphanumeric Code
 Alphanumeric codes (also known as character codes) are
defined as binary codes used to represent alphanumeric data.

 The codes write alphanumeric data, including letters of the


alphabet, mathematical symbols, numbers, and punctuation
marks, in a form that is easily understood by a computer.

 The most common alphanumeric codes used these days are


1. ASCII code (American Standard Code for Information Interchange)
2. EBCDIC code (Extended Binary Coded Decimal Inter change code)
3. UNICODE
Alphanumeric Code
 ASCII code (American Standard Code for
Information Interchange)

 Most commonly used representation

 It is a seven-bit code based on the English alphabet.

 In 1967 this code was first published and since then it is being modified
and updated.

 ASCII is a character encoding that uses numeric codes to represent characters.


These include upper and lowercase English letters, numbers, and punctuation
symbol
Alphanumeric Code
• ASCII code (American Standard Code for
Information Interchange)

• As ASCII uses 7 bits of a byte to represent a character , so it can


represent 27=128 characters (Standard Characters)
• ASCII sets the most significant bit as a parity bit or as 0
• Extended ASCII is an 8 bits uses the most significant bit and can allow
for the representation of 256 characters
• ASCII is less demanding on memory use than Unicode

• For example, the ASCII code for lower case z is 122 and is shown
below
Alphanumeric Code
 ASCII code (American Standard Code for Information Interchange)

 Numbers 0 to 9
 ASCII 0110000 (30hex) to 0111001 (39hex)

 Alphabets a to z
 ASCII 1100001 (61hex) to 1111010 (7Ahex)

 Alphabets A to Z
 ASCII 1000001 (41hex) to 1011010 (5Ahex)

 Control Characters (not seen on the screen and are executable


codes)
 ASCII 0000000 (0hex) to 0011111 (1Fhex)
Alphanumeric Code
 Extended ASCII code (American Standard Code for Information
Interchange)

• In 1981, IBM developed an extension of 8-bit ASCII code, called "code page
437", in this version were replaced some obsolete control characters for
graphic characters.
• Added 128 new symbols, signs, graphics and Latin letters, all punctuation
signs and characters needed to write texts in other languages, ​such as
Spanish ((Non Standard Characters)
• This is because extended ASCII uses eight bits to represent a character as
opposed to seven in standard ASCII (where the 8th bit is used for error
checking).
• The maximum number of characters that can be represented in extended
ASCII is 256

58
Alphanumeric Code
 EBCDIC code (Extended Binary Coded Decimal Inter change code)
 IBM invented this code to extend the Binary Coded
Decimal which existed at that time.

 All the IBM computers and peripherals use this code.

 It is an 8-bit code and therefore can accommodate 256


characters.

59
Alphanumeric Code
 Unicode
 Unicode is the newest concept in digital coding.

 Leading technological giants have adopted this code for its uniqueness

 It is a universal character set.

 It is aimed to include all the characters needed for any writing system or language.

 Unicode uses 8-bit, 16-bit or 32-bit encoding. so it can represent 28 , 216, , 232 ,
characters
respectively.

 Unicode represents a wide range of characters including different languages, mathematical symbols and
emojis

 Unicode can represent a greater range of characters than ASCII

 Unicode occupies more space and is more demanding on memory than ASCII

60
Error Detection

 Digital Systems are very Reliable

 Errors during storage or transmission

 Parity Bit
 Even Parity
 Odd Parity
Odd Parity Error Detection
 Original data 10011010
 With Odd Parity 110011010

 1-bit error 110111010


 Number of 1s are even indicating 1-bit error

 Issues in this technique:


• 2-bit error 110110010
• Number of 1s are odd indicating no error

• 3-bit error 100110010


• Number of 1s are even indicating error
Thanks

You might also like