Number Systems, Operations
and Codes
Chapter 02
Division
• The numbers in a division are dividend ,the
divisor and quotient.
• Division operation in computer is accomplished
using subtraction. Subtraction is done with an
adder, division can also be accomplished with
an adder.
• The result of a division is called quotient. The
quotient is the number of times that the divisor
will go in dividend.
Division
• For Example: dividing 21 by 7?
2 1
7
1 4
7
7
7
• Quotient= 3
• Divide 01100100 by 00011001?
• Divide 00110000 by 00001100?
Hexadecimal Numbers
• The hexadecimal number system has sixteen
character; used as a compact way of
displaying or writing binary number (easy to
convert b/w binary and hexadecimal).
• The hexadecimal number system consist of
digit 0-9 and letters [Link] has a base of
sixteen; composed of 16 numeric and
alphabetic character
Hexadecimal Numbers
Binary to Hexadecimal
• Converting a binary number to hexadecimal is
a straightforward procedure .
• Simply break the binary number into 4-bit
groups, starting at the right most bit and
replace each 4bit group with equivalent
hexadecimal symbol.
• For example: 1100101001010111= (CA57)
• 111111000101101001=??
Hexadecimal To Binary
• To convert from a hexadecimal number to
binary number, reverse the process and
replace each hexadecimal symbol with
appropriate 4 bits.
• For example: 10A4 = (1000010100100)
• CF8E= ???????
• 9742=???????
Hexadecimal To Decimal
• One way:
• Hexadecimal Binary Decimal
• 1C (00011100) 28
• A85 ( ) ___
• F4A ( ) ____
Hexadecimal To Decimal
• Another way: multiply the decimal value of
each hexadecimal digit by its weight and then
take sum of these products.
• For Example:
(E5) = (Ex161)+ (5x160)=(14x16)+(5X1)=
224+5=229
Hexadecimal To Decimal
• Convert Hexadecimal to decimal?
• 6BD
• B2F8
• 60A
• 9FCA
• FCD4
• 1BAF4CD
Decimal To Hexadecimal
• Repeated division of a decimal number by 16
will produce the equivalent hexadecimal
number, formed by the remainder of the
division.
• The procedure is similar to repeated division
by 2 (decimal to binary)
Decimal To Hexadecimal
• Convert following ?
• 42
• 85
• 198
• 560
• 1278
Hexadecimal addition
• In addition (0-------9)16 = (0-------9)10 and hexadecimal
• (A-------F)16 = (10-------15)16
• When adding two hexadecimal number consider following rules.
• In any given column of an addition problem, think of the two
hexadecimal digit in terms of their decimal values. 5 16 = 5 10
and C16 = 1210
• If the sum of these two digit is 15 or less, bring down the corresponding
hexadecimal digit.
Hexadecimal addition
• If the sum of these two digits is greater than
1510 bring down the amount of the sum that
exceeds 1610 and carry a 1 to the next column.
Hexadecimal addition
• Add the following hexadecimal numbers:
• 23 + 16
• 58 + 22
• 2B + 84
• DF + AC
• 4C + 3A
• 18 + 34
• 3F + 2A
Hexadecimal Subtraction
• 2’s complement allows you to subtract by
adding binary number.
• Since a hexadecimal number can be used to
represent a binary number, it can also be used
to represent the 2’s complement of a binary
number.
• There are three ways to get the 2’s
complement of a hexadecimal number.
Hexadecimal Subtraction
• Method 1:
• Convert the hexadecimal number to binary .Take
the 2’s complement of the binary .convert result to
hexadecimal .
• For example: Subtract (84- 2A)
2A= 00101010
2’s complement= 11010110 = D6
84 + D6 = 5A
(Drop carry, as in 2’s complement addition)
Hexadecimal Subtraction
• Subtract following hexadecimal numbers?
• 84 – 2A
• C3- 0B
• Subtract 173 from BCD.
• 75 – 21
• 94 – 5C
Octal Numbers
• Like hexadecimal number system ,the octal
number system provides a convenient way to
express binary numbers and codes.
• However it is used less frequently than
hexadecimal in conjunction with computer and
microprocessor to express binary quantities for
I/O
• The octal no has a base of 8 .it composed of 8
digit
Octal-To-Decimal
•The octal no system has a base of eight, such successive digit
position is an increasing power of eight, beginning in the right most
column.
•For example: (2374)8
2 3 7 4
(2 X 83) (3X 82) (7 X 81) (4 X 80)
1024 192 56 4
(1276)10
Decimal-To-Octal
• A method of converting a decimal number to
an octal number is the repeated division by 8
method, which is similar to the method used
in the conversion of decimal no to binary or to
hexadecimal.
• For example: (359)8 to ( )10
Octal to binary
• Each octal digit can be represented by a [Link]
binary number.
• Very easy way to convert from octal to binary ,
each digit can be represent by three bits .
• For example:
0 1 2 3 4
000 001 010 011 100
Binary to octal
• Conversion of a binary number to an octal
number is the reverse of the octal-to-binary
conversion.
• Start with right most group of three bits and
moving from right to left convert each 3 bit
group to the equivalent octal digit.
• For example: convert (110101)
110 101
6 5
Binary to octal (example)
• Convert the following binary number?
• 110101111
• 1001100010
• 10111111001
• 111000110
• 100110011010
• 011010000100
• 110101
Binary Coded Decimal
• BCD is a way to express each of the decimal digit
with a binary code.
• There are only ten code group in BCD system ,so
it is very easy to convert b/w decimal and BCD.
• BCD provides an excellent interface to binary
system.
• Examples of such interface are keypad inputs
and digital readouts.
The 8421 BCD Code
• The 8421 code is a type of BCD [Link]
means each decimal digit 0 through 9 is
represented by a binary code of four bits.
• The 8421 indicates the binary weights of the
four bits (-------------)
0 1 2 3 4 ……
0000 0001 0010 0011 0100
What are the invalid codes in 8421 BCD code??
BCD Conversion
• Convert following decimal no to BCD?
• 35 (0011 0101 )
• 98
• 170
• 2469
• Convert following BCD codes to decimal?
• 10000110 (8 6 )
• 001101010001
• 1001010001110000
• 100000100010011101101
BCD Addition
• BCD is a numerical code and can be used in
arithmetic operation.
• Addition is most important operation because
other operation (-,*,/) can be accomplished by
addition.
• Rules to add two BCD numbers:
• Step1: add the two BCD number, using rules
for binary addition
BCD Addition
• Step 2: if a 4-bit sum is equal to or less than 9,
it is a valid BCD number.
• Step 3:if a 4-bit sum is greater than 9 ,or if a
carry out of the 4 bit group is generated ,it is
an invalid result. Add 6(0110) to the 4 bit sum
in order to skip the invalid state. If a carry
results when 6 is added , simply add the carry
to the next 4-bit group.
BCD Addition
• Add following BCD number:
• 0011 + 0100
• 00100011 + 00010101
• 10000110 + 00010011
• 010001010000 + 010000010111
• 1001000001000011+ 0000100100101
BCD Addition
• Add following BCD number:
• 1001 + 0100
• 1001 +1001
• 00010110 + 00010101
• 01100111 + 01010011
• 01001000 + 00110100
Digital Codes.
• Many specialized codes are used in digital
system.
• Some codes are strictly numeric ,like BCD and
others are alphanumeric; they are used to
represent numbers, letters, symbols and
instructions.
• In this section we shall discuss about Gray
code, ASCII code and Unicode.
Gray Code
• Gray code is unweighted and is not an
arithmetic code; there are no specific weights
assigned to the bit position.
• The important feature of the gray code is it
exhibits only a single bit change from one
code word to the next in sequence..
• Like binary numbers, the gray code can have
any number of bits.
Binary to Gray code
• The MSB in the Gray code is the same as the
corresponding MSB in the binary number.
• Going from left to right , add each adjacent
pair of binary code bits to get the next gray
code bit. discard carries
Gray-to-Binary
• The MSB in binary code is the same as the
corresponding bit in the gray code.
• Add each binary code bit generated to the
gray code bit in the next adjacent position.
Discard carries.
Alphanumeric Codes
• ASCII Code (7 bit)
• Extended ASCII Code (8 bit)
• Unicode (16 bit)
Q&A