You are on page 1of 42

Lecture Two

By

Dr. Noor Abdul Khaleq Z.


19/11/2023
Content
❑Decimal Numbers.
❑Binary Numbers.
❑Binary-to-Decimal Conversion.
❑Decimal-to-Binary Conversion.
❑Binary Arithmetic.
❑Complements of Binary Numbers.
❑ Hexadecimal Numbers and Arithmetic.
❑Binary-to-Hexadecimal Conversion
❑Hexadecimal to Binary Conversion
❑Hexadecimal-to-Decimal-Conversion
❑Decimal-to-Hexadecimal Conversion
❑Octal Numbers and Arithmetic.
❑ Octal-to-Decimal Conversion
❑Decimal-to-Octal Conversion
❑Octal-to-Binary Conversion
❑Binary-to-Octal Conversion
Decimal Numbers

❑ The decimal number system employs 10 symbols to represent numbers


with a base of 10. It has ten digits, 0 through 9.
❑ We use two or more digits to express a quantity greater than 9, where the
position of each digit indicates the magnitude of the quantity represented
(weight).
❑ The weights of decimal numbers are powers of ten that increase from
right to left beginning with 10 0 =1.
Decimal Numbers 10 5 10 4 10 3 10 2 10 1 10 0.
❑ For fractional decimal numbers, the column weights are negative powers
of ten that decrease from left to right
10 2 10 1 10 0. 10 -1 10 -2 10 -3 10 -4
Decimal Numbers
❑The value of a decimal number is the sum of the digits after each digit has
been multiplied by its weight. Thus, the number 5319 can be expressed as

❑ Example: Express the decimal number 480.52 as a sum of the values of each
digit.
❑ Solution:
480.52 = (4 x 10 2 ) + (8 x 10 1 ) + (0 x 10 0 ) + (5 x 10 -1 ) +(2 x 10 -2 )
= (4 x 100 ) + (8 x 10 ) + (0 x 1 ) + (5 x 0.1 ) +(2 x 0.01 )
= 400 + 80 + 0 + 0.5 + 0.02
Binary Numbers
❑ For digital systems, the binary number system is used.
❑ It has only two digits (bits) 0 and 1, hence, It is a base-two system.
❑ The column weights of binary numbers are powers of two that increase from
right to left beginning with 2 0 =1.

252423222120

❑ For fractional binary numbers, the column weights are negative powers of two
that decrease from left to right

2 n-1 ……2 2 2 1 2 0. 2 -1 2 -2 2 -3 2 -4 …… 2 -n

❑ Where n is the number of bits from the binary point


Binary Numbers
❑ A binary counting sequence for numbers from zero to fifteen is shown.

❑ Four bits are required to count from zero to 15. In general, with n bits you can
count up to a number equal to 2n - 1.
Decimal-to-Binary Conversion.
There are two methods for converting whole numbers from decimal to
binary.
The First Method: Sum-of-Weights
❑ Determine the set of binary weights whose sum is equal to the decimal
number to find the binary number that is equivalent to a given decimal
number.
❑ The decimal number 9, for example, can be expressed as the sum of
binary weights as follows: 9 = 8 + 1 or 9 = 23 + 20 =1001
❑ Example: Convert the following decimal numbers to binary:
12 , 25 ,58 , 82
❑ Solution:
12 = 8 +4 = 23 + 22 -----------------------------------1100
25 = 16 + 8 + 1 = 24 + 23 + 20------------------------11001
58 = 32 + 16 + 8 +2 = 25 + 24 + 23 + 21 ------------111010
82 = 64 + 16 + 2 = 26 + 24 + 21 ----------------------1010010
Decimal-to-Binary Conversion.
Converting Decimal Fractions to Binary use First Method
❑ The sum-of-weights method can be applied to fractional decimal numbers,

❑ Example: Convert the following decimal fraction to binary:


0.625 , 0.6875 , 13.625
❑ Solution:

0.625 = 0.5 + 0.125 = 2-1 + 2-3 --------------------------------- 0.101

0.6875 = 0.5 + 0.125 + 0.0625 = 2-1 + 2-3 + 2-4 -------------- 0.1011

13.625 = 8 + 4 +1 . +0.5 + 0.125 = 23 + 22 + 20 .+ 2-1 + 2-3 -------------- 1101.101


Decimal-to-Binary Conversion.
The second Method: Repeated Division-by-2
❑ To convert a whole number from decimal to binary, divide the decimal
number by 2 until the quotient is 0. Then, the Remainders form the binary
number.

❑ Example: Convert the decimal number 12 to binary


❑ Solution:
❑ Converting Decimal Fractions to Binary use Second Method

❑ Decimal fractions can be converted to binary by repeated multiplication by 2.

❑ Example: Convert the decimal fraction 0.188 to binary.

❑ Solution:

= 0. 00110
Binary-to-Decimal Conversion
❑ The decimal equivalent of any binary number can be determined adding the
weights of all bits that are 1 and discarding the weights of all bits that are 0.

❑ Example: Convert the binary number 100101.01 to decimal

❑ Solution:
2 5 2 4 2 3 2 2 2 1 2 0. 2 -1 2 -2
32 16 8 4 2 1 . 0.5 0.25
1 0 0 1 0 1. 0 1
32 + 4 + 1. + 0.25
= 37.25
Binary Arithmetic
❑ Binary arithmetic is essential in all types of digital systems. To understand
these systems, you must know the basics of binary Addition, Subtraction,
Multiplication, and Division.

Binary Addition
❑ The four basic rules for adding binary digits (bits) are as follows:
0 + 0 = 0 Sum of 0 with a carry of 0
0 + 1 = 1 Sum of 1 with a carry of 0
1 + 0 = 1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1

❑ Notice that the first three rules result in a single bit and in the fourth rule
the addition of two 1s yields a binary two (10). When binary numbers are
added, the last condition creates a sum of 0 in a given column and a carry
of 1 over to the next column to the left.
Binary Arithmetic
❑ Example: Add 11 + 1
❑ Solution:

❑ Example : Add 11101 to 11011


❑ Solution:
Binary Arithmetic
Binary Subtraction
❑ The four basic rules for subtracting bits are as follows:
0-0=0
1-1=0
1-0=1
0-1=1 with a borrow of 1

❑ When subtracting numbers, you sometimes have to borrow from the next
column to the left. A borrow is required in binary only when you try to
subtract a 1 from a 0.
❑ In this case, when a 1 is borrowed from the next column to the left, a 10 is
created in the column being subtracted, and the last of the four basic rules
just listed must be applied
Binary Arithmetic
❑ Example: Subtract 011 from 101
❑ Solution:

❑ Example : Subtract 1010 from 1100


❑ Solution:
Binary Arithmetic
Binary Multiplication
❑ The four basic rules for multiplying bits are as follows:

0×0=0
0×1=0
1×0=0
1×1=1

❑ Multiplication is performed with binary numbers in the same manner as


with decimal numbers. It involves forming partial products, shifting each
successive partial product left one place, and then adding all the partial
products
Binary Arithmetic
❑ Example: Perform the following binary multiplications for
(a) 11 × 11 (b) 111 × 101
❑ Solution:

❑ Example: Perform the following binary multiplications for 100 × 011


❑ Solution:
Binary Arithmetic
Binary Division
❑ Division in binary follows the same procedure as division in decimal
❑ Example: Perform the following binary division for (a) 110 ÷ 11 (b) 110 ÷ 10
❑ Solution:

❑ Example: Perform the following binary division for 10010 ÷ 11


❑ Solution:
Complements of Binary Numbers
❑ The 1’s complement and the 2’s complement are important to represent the
negative numbers.

The 1’s Complement


❑ The 1’s complement of a binary number is found by changing all the 1s to
0s and all 0s to 1s show in the example below
Complements of Binary Numbers

The 2’s Complement


❑ The 2’s complement of a binary number is found by two method

Method 1:
❑ Adding 1 to the LSB of the 1’s complement.
2’s complement = (1’s complement) + 1

Method 2:
❑ take the 1’s complements of all the bits to the left of the least significant 1.
Complements of Binary Numbers
❑ Example: Find the 2’s complement of 10111000

❑ Solution:
Binary Subtraction using 2’s complement
❑ Instead of subtracting a number, we can add its 2’s complement, and
discard the last carry.

❑ Example: subtract 1010 from 1101.


❑ Solution:
1101 1101
- 1010 + 0110 (2’s complement of 1010)
0011 10011

❑ The advantage of using 2’s complement method in subtraction is the


reduction of hardware. Instead of having digital circuits that directly add
and subtract, only adding-type circuits are needed
Hexadecimal Numbers.
❑ The hexadecimal number system has a base of 16; that it is composed of 16
numeric (0-9 digits) and alphabetic (A-F letters) characters.
❑ It is used primarily as a compact way of displaying or writing binary numbers
because it is very easy to convert between binary and hexadecimal.
❑ It can be used to represent large numbers with fewer digits.
❑ Each hexadecimal digit represents a 4-bit binary number.
Counting in Hexadecimal Numbers
❑ Count in hexadecimal once you get to F by starting over with another
column and continue as follow:

❑ With two hexadecimal digits, you can count up to FF. To count beyond FF,
three hexadecimal digital are needed where the maximum 3-digit
hexadecimal number is FFF
Binary-to-Hexadecimal Conversion
❑ To convert a binary number to a hexadecimal, break the binary number into 4-
bit groups. Then, starting at the right-most bit and replace each 4-bit group with
equivalent hexadecimal symbol.
❑ Example: Convert the following binary numbers to hexadecimal:
a) 1100101001010111 b)11111100010110100
❑ Solution:

❑ Note: two zeros have been added in (b) to complete a 4-bit group at the left.
Hexadecimal to Binary Conversion
❑ To convert from a hexadecimal number to binary number, replace each
hexadecimal symbol with the corresponding four bits.
❑ Example: Determine the binary numbers for the following hexadecimal
numbers:
a) 10A4 b)CF8E c)9DB5
❑ Solution:

c)
Hexadecimal-to-Decimal-Conversion
❑ There are two methods for converting whole numbers from Hexadecimal to
Decimal.
Method1:
❑ Convert the hexadecimal number to binary number and then convert from
binary to decimal.
❑ Example: Convert the hexadecimal numbers to decimal.
(a)1C b) A85)
❑ Solution:
Hexadecimal-to-Decimal-Conversion
Method 2:
❑ Multiply the decimal value of each hexadecimal digit by its weight and then
take the sum of these product.
❑ The weights of a hexadecimal number are increasing powers of 16 from right
to left

❑ Example: Convert the hexadecimal numbers (7DE) to decimal.


❑ Solution:
Decimal-to-Hexadecimal Conversion
❑ Repeated division of a decimal number by 16 will produce the equivalent
hexadecimal number, formed by the remainders of the divisions.
❑ The first remainder produced is the least significant bit (LSB).
❑ Each successive division by 16 produces a remainder that that becomes a digit
in the equivalent hexadecimal number
❑ Example: Convert the decimal number 650 to hexadecimal.
❑ Solution:
Hexadecimal Addition
❑ When adding two hexadecimal values, use the following rules:
1. In any given column of an addition problem, think of the two hexadecimal digits
in terms of their decimal values. For example, 516 = 510 , A16 = 1010.
2. If the sum of these two digits ≤ 1516, bring down the corresponding hexadecimal
digit.
3. If the sum of these two digits > 1516, bring down the amount of the sum that
exceeds 1610 and carry a 1 to the next column.
❑ Example: Add the following hexadecimal numbers:
(a) (2B)16 + (84)16, (b) (DF)16 + (AC)16
❑ Solution:
The 2’s complement of a hexadecimal number
❑ There are three methods to get the 2’s complement of a hexadecimal number.
Method 1 is the most common, while the other methods are alternatives.
Method1:
Convert the hexadecimal number to binary. Then, take the 2’s complement of the
binary number, and convert the result to hexadecimal.
The 2’s complement of a hexadecimal number
Method 2:
Subtract the hexadecimal number from the maximum hexadecimal number and
add 1.
The 2’s complement of a hexadecimal number
Method 3:
Write the sequence of single hexadecimal digits. Then, write the sequence in
reverse below the forward sequence. The 1’s complement of each hexadecimal
digit is the digit directly below it; add 1 to the resulting number to get the 2’s
complement.
Hexadecimal Subtraction
❑ The 2’s complement allows you to subtract by adding numbers.

❑ Example: Subtract the following hexadecimal numbers:


a) (84)16 – (2A)16 b)(C3)16- (0B)16
❑ Solution:
Octal Numbers

❑ The octal number system provides a convenient way to express binary numbers
and codes.
❑ The octal number system is used less frequently than hexadecimal in
conjunction with computers and microprocessors to express binary quantities
for input and output purposes.
❑ The octal number system consists of eight digits, which are 0,1,2,3,4,5,6,7
❑ To count above 7, begin another column and start over: 10, 11, 12, 13, 14, 15,
16, 17, 20, 21, …
❑ Sometimes, you may see an “o” or a “Q” following an octal number
Octal-to-Decimal Conversion

❑ The evaluation of an octal number in term of its decimal equivalent is


accomplished by multiplying each digit by its weight and summing the
products.
❑ Example: Convert the octal number 2374 to decimal.
❑ Solution:
Weight: 83 82 81 80
Octal number: 2 3 7 4
Decimal-to-Octal Conversion

❑ A method to convert a decimal number to an octal number is the repeated


division by 8 method.
❑ Each successive division by 8 provides a remainder that becomes a digit in the
equivalent octal number

❑ Example: Convert the decimal number 359 to octal.


❑ Solution:
Octal-to-Binary Conversion

❑ Each octal digit is represented by three bits as shown below

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

❑ To convert an octal number to a binary number, replace each octal digit with
appropriate three bits.
❑ Example: Convert 7526 to binary
❑ Solution:
7 5 2 6
111 101 001 110

7527 = 111101001110
Binary-to-Octal Conversion

❑ To convert a binary number to an octal number, start with right-most group of


three bits and, moving from right to left, convert each 3-bit group to the
equivalent octal digit

❑ Example: Convert each of the following binary numbers to octal:


(a) 100110011010 (b) 11010000100
❑ Solution:
(a) 100 110 011 010
4 6 3 2

(b) 011 010 000 100


3 2 0 4
Octal Addition
❑ Following octal addition table will help you to handle octal addition.
+ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 10
2 2 3 4 5 6 7 10 11
3 3 4 5 6 7 10 11 12
4 4 5 6 7 10 11 12 13
5 5 6 7 10 11 12 13 14
6 6 7 10 11 12 13 14 15
7 7 10 11 12 13 14 15 16

❑ Example: Add the following octal numbers: 5647 + 7261


❑ Solution:
Octal Addition
Note: If the sum of the two digits ≤ 8, bring down the corresponding octal digit.
While, if the sum of the two digits > 8, bring down the amount of the sum that
exceeds 88 and carry a 1 to the next column

❑ Example: Add the following octal numbers: 770 + 665

❑ Solution:
Octal Subtraction
❑ The subtraction of octal numbers follows the same rules as the subtraction of
numbers in any other number system.
❑ The only variation is in borrowed number. In the decimal system, you borrow a
group of 10. In the binary system, you borrow a group of 2. In the octal system
you borrow a group of 8.
❑ Example: subtract the following octal numbers:
a) 1066 - 776 b) 5142 - 2546
❑ Solution:

You might also like