Anda di halaman 1dari 27

Learning outcomes

• Review number systems


• Explain how powers of ten are used in the decimal system
• Determine the weight of each digit in a decimal number
• Convert from decimal to binary and from binary to decimal
• Count in the binary number system
• Determine the 1's and 2's complements of a binary number
• Express negative binary numbers in 2' s complement
• Perform arithmetic operations to binary numbers
• Convert between the binary and hexadecimal number systems
• Convert between the binary and octal number systems
• Convert between decimal and hexadecimal number systems
• Convert between decimal and octal number systems

1
Number Systems
Number system – a system of base or radix, r, is a system that uses
distinct symbols for r digits.

Number or
Nr digit symbol

Base or radix

Base or radix – number of digits which can occur in the number system

Examples:
Base 10 (10 digits) Base 16 (16 digits)
Can you name more?
Base 8 (8 digits) Base 2 (2 digits)
2
Number Systems

Nr = (an-1 an-2 ….. a1 a0 . a-1 a-2 ….a-m)r

Integer part Fractional part


Radix point

Example:

In decimal: (435.301)10

3
Number Systems
Base 16 – Hexadecimal number
used for addressing in microprocessors and to express binary numbers

Base 10 – Decimal number


used in everyday life for mathematical calculations

Base 8 – Octal number


also used to represent binary numbers

Base 2 – Binary number


used in digital processing in electronic circuits 4
Decimal Number
For the decimal number system:
1. Number of digits is 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
2. The base is 10
3. The value of the digit is determined by the position of the number
(654.52)10

Decimal point

Hundreds Tens Units One One


tenth hundredth
Weights 102 101 100 10-1 10-2

Digits 6 5 4 5 2

Weighted 600 50 4 0.5 0.02 Total


5
Value 654.52
Binary Number
The binary number:
1. Has base 2 i.e. is represented by 2 digits: 0 and 1
2. The position of a 1 or 0 in a binary number indicates its weight or
value within the number.
3. The weights in a binary number are based on powers of two.

(110.10)2
Binary point

The least significant bit (LSB) is the rightmost Weights 22 21 20 2-1 2-2
binary digit which has the lowest binary weight of
a given number. Digits 1 1 0 1 0
The most significant bit (MSB) is the leftmost
binary digit which has the highest binary weight MSB LSB MSB LSB
of a given number.
6
Binary to Decimal Conversion
The decimal value of any binary number can be found by adding the weights
of all bits that are 1 and discarding the weights of all bits that are 0.

Ex. Convert (110101)2 to decimal form.

Binary 25 24 23 22 21 20 Convert the binary numbers to decimal:


Weights
1. 10010001
Weight 32 16 8 4 2 1 2. 0.1011
Value 3. 1101.11
Binary 1 1 0 1 0 1
Number
Decimal 32 16 0 4 0 1 Total
Value (53)10

7
Decimal to Binary Conversion
2 methods of converting a decimal number to binary:
1. Sum of weights
2. Repeated division by two.

1. Sum of weights method.


Determine the set of binary weights whose sum is equal to the decimal number.

Convert (24)10 to binary


Disadvantage:
Binary 24 23 22 21 20
Weights 1. Time consuming
Weight 16 8 4 2 1
Value Convert (1456)10 to binary
Binary 1 1 0 0 0
Number
8
Answer: (11000)2
Decimal to Binary Conversion
2. Repeated-Division-by-2 method

Converting (18)10 to binary


Procedure:
2 18
1. Divide the quotient by two and record
2 9 R 0 (LSB)
the remainder.
2 4 R1
2. Repeat step (a) until the quotient is 2 2 R0
equal to zero (0). 2 1 R0
3. The first remainder produced is the LSB 0 R 1 (MSB)
in the binary number and the last
remainder (R) the MSB. Therefore, (18)10 = (10010)2
4. The binary number is then written (from
left to right) with the MSB occurring first. Convert the following decimal
numbers to binary:
(a) 12 (c) 82
(b) 25 (d) 58 9
Decimal fractions to Binary
Sum-oF-Weights:

The sum-of-weights method can be applied to fractional decimal numbers:

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

Repeated multiplication by 2

For example: Convert 0.3125 to binary,

1. Begin by multiplying 0.3125 by 2 and then multiplying each resulting


fractional part of the product by 2 until the fractional product is zero or
until the desired number of decimal places is reached.

2. The carry digits, or carries, generated by the multiplications produce


the binary number.

3. The first carry produced is the MSB, and the last carry is the LSB. 10
Decimal fractions to Binary

14
11
Binary Arithmetic - Addition
CARRY: C3 C2 C1 C0
Word A: A3 A2 A1 A0
Addition of two 4-bit words A and B
Word B: B3 B2 B1 B0
SUM: S3 S2 S1 S0

The four basic rules for adding binary Example of binary addition:
digits (bits) are as follows:
Decimal Binary
Addition Rules 5 101
A+B Sum Carry +3 +011
0+0 0 0 8 1000
0+1 1 0
Try: (158)10 + (12)10
1+0 1 0
(111)2 + (1011)2
1+1 0 1 (1010)2 + (1010)2 12

( 23)10 + ( 15)10
Binary Arithmetic - Subtraction
Two efficient methods that can be implemented with hardware are:
1. Subtraction using 1’s complement.
2. Subtraction using 2’s complement.

Complements are used in digital computers for simplifying the subtraction operation
and for logical manipulation.

1’s complement of binary numbers


The 1's complement of a binary number is found by changing:
1. all 1s to 0s and
2. all 0s to 1s,

1 0 1 1 0 1 0 1
Obtain the 1’s complement of
(11010110)2 and (654)10 13
0 1 0 0 1 0 1 0
Binary Arithmetic - Subtraction
2’s complement of binary numbers

The 2's complement of a binary number is found by adding 1 to the LSB of the
1's complement.

2's complement = (1's complement) + 1

Decimal number (25)10


Binary number 11001 Obtain the 2’s complement of:
1’s complement 00110
1. (110111)2
00110
Add 1 00001 + 2. (56)10
2’s complement 00111

14
Binary Arithmetic - Subtraction

The subtraction of two n-digit unsigned numbers M - N in base 2 can be done


as follows:
Minuend M
-
Subtrahend N

1. Add the minuend M to the 2’s complement of the subtrahend N.

2. If M ≥ N, the sum will produce an end carry which is discarded

3. If M < N, the sum does not produce an end carry the result is equal to the
2’s complement of (N - M). To obtain the correct answer, take the 2's
complement of the sum and place a negative sign in front.

15
Binary Arithmetic - Subtraction
Given two binary numbers X = 1010100 and Y = 1000011, perform the
subtractions: X – Y and Y – X using 2’s complements.

Try X – Y and Y – X when


1. X = 78 and Y = 87;
2. X = 45 and Y = 45
3. X = 19 and Y = 49
All numbers are in base
10.

16
Hexadecimal Numbers
The hexadecimal number system
1. Has a base of sixteen; that is, it is composed of 16 numeric and
alphabetic characters: 0,1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
2. Has weights based on powers of 16
3. The position of a character in the number indicates its weight or value
within the number

Weights 162 161 160 . 16-1 16-2

Hexadecimal point

Example: (14A)16, (BA)16

17
Hexadecimal Numbers
Decimal Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3 Each 4-bit binary number
4 0100 4 can be represented by a
5 0101 5 hexadecimal number.
6 0110 6 Ex.
7 0111 7
(0000)2 – (0)16
8 1000 8
9 1001 9 (1100)2 - CH
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
18
15 1111 F
Hexadecimal to Binary
Converting Hexadecimal to Binary

Because each hexadecimal digit can be represented by a four-bit binary number it


is very easy to convert from hexadecimal to binary.
Replace each hexadecimal digit with the appropriate four-bit binary number.

Examples

A 3 16 = (1010 0011) 2

(37.12) 16 = (00110111.00010010) 2

Convert the following to binary form


ABCH; 1B0H; DE4H; AC5H
19
Binary to Hexadecimal
Converting Binary to Hexadecimal

Break the binary digits into groups of four starting from the binary point and
convert each group into its appropriate hexadecimal digit using the
conversion table.
For whole numbers, it may be necessary to add a zero as the MSB in order to
complete a grouping of four bits.

Example:
(101001)2 => (00101001)2 => 29H
(110 1100 1111)2 => (0110 1100 1111)2 => 6CFH

Convert the following to hexadecimal form


(11011111)2; (011001111)2; (110111)2; (011001)2
20
Hexadecimal to Decimal
Converting Hexadecimal to Decimal
To convert a hexadecimal number to its decimal equivalent - multiply the decimal
value of each hexadecimal digit by its weight and then take the sum of these
products.
Convert AB2 to Decimal

Hexadecimal 162 161 16 Convert the following


Weights 0
hexadecimal numbers to
Weight Value 256 16 1 decimal:
Hexadecimal A B 2 1. ADF
Number
2. ACF
Decimal 10 11 2
Value of Hex 3. 32A
Decimal 2560 176 2 4. 1234
Value
21
Answer: (1738)10
Decimal to Hexadecimal
Converting Decimal to hexadecimal
Example: (854)10 to hex
Successive division of decimal number by 16.

1. Divide the quotient by 16 and record the 16 854


remainder (R). 16 53 R 6 (LSB)
2. Repeat step (a) until the quotient is 16 3 R5
equal to zero (0). 0 R 3 (MSB)
3. The first remainder produced is the LSB
in the hexadecimal number and the last Answer: 356H
remainder the MSB. Convert the following to
4. The hexadecimal number is then written hexadecimal:
(from left to right) with the MSB 1. (54)10
occurring first.
2. (81)10
22
3. (719)10
Octal Numbers
The octal number system
1. Has a base of eight; that is, it is composed of 8 numeric characters: 0,1,
2, 3, 4, 5, 6, 7
2. Has weights based on powers of 8
3. The position of a character in the number indicates its weight or value
within the number

Octal 82 81 80 . 8-1 8-2


Weights

Hexadecimal point

Examples : (33)8; (1235)8


23
Octal to Binary
The primary application of octal numbers is
representing binary numbers, as it is easier to
read large numbers in octal form that in binary
Octal Binary Digit form.
Digit Because each octal digit can be represented by
0 000 a three-bit binary number it is very easy to
1 001 convert from octal to binary.
2 010
Conversion of octal to binary
3 011
4 100 13 8 = (001011) 2
5 101 (37.12) 8 = (011111. 001010) 2
6 110
7 111 Convert the following numbers to
binary:
(254)8; (265)8; (159)10; (954)10 24
Binary to Octal
Converting Binary to Octal

Break the binary digits into groups of three starting from the binary point and
convert each group into its appropriate octal digit.

For whole numbers, it may be necessary to add a zero as the MSB in order
to complete a grouping of three bits.
Note that this does not change the value of the binary number.

Examples: Convert the following binary


numbers to octal:
1.Converting (010111) 2 to Octal
(11011111)2; (011001111)2;
(110111)2; (011001)2
111 = 7 (LSB)

010 = 2 (MSB)

thus, (010111) 2 = (27) 8 25


Octal to Decimal
To express the value of a given octal number as its decimal equivalent we just
need to sum the digits after each has been multiplied by its associated
weight.
Convert (237.04) 8 to decimal form.

Weights 82 81 80 8-1 8-2


Weight Value 64 8 1 0.125 0.015625
Octal 2 3 7 0 4
Number
Decimal 128 24 7 0 0.0625 Total
Value (159.0625)10

Answer: (159.0625)10

Convert to decimal form:


(125) 8 (568) 8 (25) 8
26
Decimal to Octal
Repeated-Division-by-8 method
a. Divide the quotient by eight and record the remainder.
b. Repeat step (a) until the quotient is equal to zero (0).
c. The first remainder produced is the LSB in the octal number and the last
remainder (R) the MSB. Accordingly, the octal number is then written
(from left to right) with the MSB occurring first

Converting (359) 10 to Octal


Convert the following to octal:
8 359
1. (514)10
8 44 R 7 (LSB)
2. (381)10
8 5 R4
8 0 R 5 (MSB) 3. (71)10

(359) 10 = (547) 8
27

Anda mungkin juga menyukai