Chapter 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

Chapter 1

Number systems
Number Systems

Number representations
Computations
Common codes
Part 1
Number representations
Number representations

A number in the number system is:


created by one or more digits.
comprised of the integer part and fractional
part separated by the radix point
(or base point)
Number representations

The weight of each digit


The weight = baseposition
The last digit on the left: the most significant digit
(MSD)

The last digit on the right: the least significant digit


(LSD)
The value of the number =  (digit * its weight)
Number representations

1. Decimal system
2. Binary system
3. Hexadecimal system
4. Octal system
Number representations

1. Decimal system
 Symbol: D
 Base: 10
 Digits used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Example:
11.25D
19D
Number representations
2. Binary system
 Symbol: B
 Base: 2
 Digits used: 0, 1.
Example:
101011B
1011.01B
Number representations

Convert the number in binary system into decimal system


 Calculate the value of the binary number.
Example:
1011.01B = 1x23 + 0x22 + 1x21 + 1x20
+ 0x2-1 + 1x2-2
= 1x8 + 0x4 + 1x2 + 1x1 + 0x0.5 + 1x0.25
= 11.25D
Number representations

Example:
Convert the following binary numbers into decimal
system.

a/ 1010.1101B
b/ 1001.0011B
Ans. a/ 10.8125D
b/ 9.1875D
Number representations
Convert the number in decimal system into binary system
 For an integer: divide the integer by 2 until the quotient
is zero. Then, collect the remainders upward

Example:
Convert 19D into B
 19D = 10011B
Number representations
Example:
Convert the following decimal numbers into
binary system.
a/ 15D
b/ 23D

Ans. a/ 1111B
b/ 10111B
Number representations

Convert the number in decimal system into binary system


 For a fraction: multiply the fraction and 2, then taking
out the integer part of the product.

Repeat the multiplication of the fraction and 2 until the


fraction is zero or reaches to an accuracy accepted. The
binary obtained is the downward collections of removed
integers.
Number representations
Example:
Convert 0.8125D into binary system.
0.8125 x 2 = 1.625  take out 1
0.625 x 2 = 1.25 take out 1
0.25 x 2 = 0.5  take out 0
0.5 x 2 = 1.0  take out 1
 The binary obtained is 0.1101B
Number representations
Example: Convert 12.69D into B.
The integer part: 12D = 1100B
The fraction:
0.69 x 2 = 1.38  take out 1
0.38 x 2 = 0.76  take out 0
0.76 x 2 = 1.52  take out 1
0.52 x 2 = 1.04  take out 1
0.04 x 2 = 0.08  take out 0
Result: 12.69D 1100.10110B
Number representations

Example:
Convert the following decimal numbers
into binary system.
a/ 16.75D
b/ 25.57D

Ans. a/ 10000.11B
b/ 11001.10010 B
Number representations

3. Hexadecimal system
 Symbol: H
 Base: 16
 Digits used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F

The digits A, B, C, D, E, F are worth 10, 11, 12, 13, 14, 15,
respectively.
Number representations

+ Convert the number in hexadecimal system into


decimal system
 Calculate the value of the hexadecimal number.
Example:
Convert 2A9H into decimal system.
2A9H = 2x162 + 10x161 + 9x160
= 2x256 + 10x16 + 9x1
= 681D
Number representations
+ Convert the number in decimal system into hexadecimal system
 Divide the decimal number by 16 until the quotient is zero.
The hexadecimal obtained is the upward collections of the
remainders.
Example: Convert 11512D into hexadecimal system.

Result: 11512D = 2CF8H


Number representations

+ Convert the number in hexadecimal system into


binary system

One digit in hexadecimal system is equivalent to


4 bits in binary system
Example:
Convert 4B7DH into binary system.
4B7DH = 0100 1011 0111 1101 B
Number representations

+ Convert the number in binary system into hexadecimal


system

 From the unit column, group 4 bits of binary number together.


Convert each group into the corresponding hexadecimal digit.
Example: Convert 10010111000110B into hexadecimal system.
10010111000110B = 10 0101 1100 0110 B
=2 5 C 6 H
= 25C6H
Number representations
Example:
Do the following conversions
1. Convert 3B7H into D
2. Convert 12315D into H
3. Convert 5E3DH into B
4. Convert 100110100111011B into H
Ans. 1/ 951 D 3/ 0101111000111101B
2/ 301B H 4/ 4D3B H
Number representations

4. Octal system

Symbol: O
Base: 8

Digits used: 0, 1, 2, 3, 4, 5, 6, 7.
Number representations

+ Convert the number in Octal system into Decimal system:

Calculate the value of the Octal number.


Example: Convert 2738 into decimal system.
2738 = 2x82 + 7x81 + 3x80

= 2x64 + 7x8 + 3x1


= 187D
Number representations
+ Convert the number in decimal system into Octal system:
 Divide the decimal number by 8 until the quotient is zero.
The hexadecimal obtained is the upward collections of the
remainders.
Example: Convert 572D into Octal system.

Result: 572D = 10748


Number representations

+ Convert the number in Octal system into Binary system:


 One digit in Octal system is equivalent to 3 bits in
binary system.
Example: Convert 7238 into binary system.
7238 = 111 010 011 B
Number representations
+ Convert the number in binary system into Octal system
 From the unit column, group 3 bits of binary number
together. Convert each group into the corresponding
Octal digit.
Example: Convert 10010111000110B into Octal system.
10010111000110B = 10 010 111 000 110 B
= 2 2 7 0 6 O
= 227068
Number representations
Example:
Do the following conversions
1. Convert 3658 into D
2. Convert 463D into O
3. Convert 6358 into B
4. Convert 100110100111011B into O

Ans. 1/ 245 D 3/ 110011101 B


2/ 717 O 4/ 46473 O
Number in different bases
Decimal Binary Octal Hexadecimal
(Base 10) (Base 2) (Base 8) (Base 16)
00 00000 00 00
01 00001 01 01
02 00010 02 02
03 00011 03 03
04 00100 04 04
05 00101 05 05
06 00110 06 06
07 00111 07 07
08 01000 10 08
09 01001 11 09
10 01010 12 0A
11 01011 13 0B
12 01100 14 0C
13 01101 15 0D
14 01110 16 0E
15 01111 17 0F
16 10000 20 10
Part 2
Computations
+ Decimal system
+ Binary system
Computations

1. Complement of “base -1”:


Given number N consisting of n digits in the base system r,
Complement of “base -1” of N is defined rn - 1 - N.
Example:
Complement 9 of 123D is: 103 - 1 - 123 = 999 - 123 = 876D
Complement 1 of 1100B is: 24 - 1 - 12 = 15 - 12 = 3 = 0011B
Complement 15 of 2CH is: 162 - 1 - 44 = 255 - 44 = 211 = D3H
Computations

To find complement 9 of a decimal number, take 9


minus each digit.
Example: Find complement 9 of 01234D
99999
-01234
98765
Result: Complement 9 of 01234 is 98765
Computations

To find complement 1 of a binary, change bit 1 to bit


0 and change bit 0 to bit 1.

Example:
Complement 1 of 1100110B is 0011001B
Computations
2. Base Complement:
Given number N consisting of n digits in the base system r,
Base complement of N is defined:
rn - N if N ≠ 0
0 if N = 0
Example:
Complement 10 of 123D is: 103- 123 = 1000 - 123 = 877D
Complement 2 of 1100B is: 24 - 12 = 16 - 12 = 4 = 0100B
Complement 16 of 2CH is: 162 - 44 = 256 - 44 = 212 = D4H
Computations
Base complement can be calculated by adding 1 in the
complement of “base -1”

Example:
Complement 9 of 456D is 543D
 Complement 10 of 456D is 543 + 1 = 544D
Complement 1 of 1011B is 0100B
 Complement 2 of 1011B is 0100B + 1 = 0101B
Complement 1 of 1000B is 0111B
 Complement 2 of 1000B is 0111B + 1 = 1000B
Computations in binary code
systems

3. Unsigned binary number:

The value of unsigned binary number ≥ 0.

An unsigned binary number n bits expresses value in

range of 0 to 2n - 1.
Computations in binary code
systems

4. Signed binary number:

Three ways to represent signed numbers


. Sign-Magnitude
. 1’s Complement
. 2’s Complement
Sign-Magnitude

 For an N-bit word, the most significant bit is the


sign bit; the remaining bits represent the magnitude
 0110 = +6
 1110 = -6
 Two values for zero
 Range for n bits: -(2n-1-1) through (2n-1-1)
1’s Complement

1’s complement:

The positive number is represented as in the common


binary form, and the MSB is “0”.

The negative number is obtained by find the 1’s


complement of the corresponding positive number.
Example: 0110B = +6D ; 1001B = -6D
2’s Complement
2’s complement:

The positive number is represented as in the common


binary form, and the MSB is “0”.

The negative number is obtained by find the 2’s


complement of the corresponding positive number.

Example: 0110B = +6D;


 2’s complement of 0110B is 1010B  1010B = -6D
2’s Complement

To take the two’s complement of a number:


 copy bits from right to left until (and including) the

first “1”
 flip remaining bits to the left
Signed binary number

Example:
1. Convert -14D into signed binary number.
+14D = 01110B
Complement 2 of 01110B is 10010B
 -14D = 10010B

2. Convert the signed binary number 11101B into D


Complement 2 of 11101B is 00011B = +3D
 11101B = -3D
Signed binary number
The MSB of the negative numbers in the signed
binary system = 1
For positive numbers, adding bits 0 to the left (in front of
MSB) does not change the number’s value.
For negative numbers, adding bits 1 to the left (in front of
MSB) does not change the number’s value.
Example:
0110B = 00110B = 000110B = … = +6D
1010B = 11010B = 111010B = … = -6D
Computations
5. Subtraction using complement:
The subtraction between two unsigned numbers M - N
(consisting of n digits) at base r is performed as follows:
Add the subtrahend M and base complement of N:
M + (rn - N) = M - N + rn
If M≥N, the sum produces the last carry
 the result obtained by ignoring the last carry.
(M - N + rn) - rn = M - N (the last carry is rn)
Computations

If M <N, the sum does not produce the last carry and
equals to rn - (N-M).
 This is complement r of (N-M).
 To obtained the result, find complement r of the sum
and put the sign “-” in front of it.
Computations

Example:
Using complement 10 to do the subtraction: 67543 - 2465
67543
+
Complement 10 of 02465 is: 9 7 5 3 5

16 5 0 7 8
Ignore the last carry: 65078  67543 - 2465 = 65078
Computations
Example:
Using complement 10 to do the subtraction 2465 - 67543
02465
+
Complement 10 of 67543 is: 3 2 4 5 7

34922
There is no last carry. Complement 10 of 34922 is 65078.
 2465 - 67543 = -65078
Computations

Example:
Using complement 2 to do the subtraction 111001 - 1010
111001
+
Complement 2 of 001010 is: 110110

11 01111
Ignore the last carry:
111001 - 1010 = 101111
Computations

Example:
Using complement 2 to do subtraction 1010 - 111001
001010
+
Complement 2 of 111001 is: 0 0 0 1 1 1

010001
There is no last carry. Find complement 2 of 010001
is 101111  1010 - 111001 = -101111
Part 3
Common Codes
Common Codes
Common Codes
Binary Coded Decimal (BCD 8421)
Used to represent the decimal digits 0 - 9.
4 bits are used.
Each bit position has a weight associated with it (weighted code).
Weights are: 8, 4, 2, and 1 from MSB to LSB (called 8-4-2-1 code).

BCD Codes:
0: 0000 1: 0001 2: 0010 3: 0011 4: 010
5: 0101 6: 0110 7: 0111 8: 1000 9: 1001
Used to encode numbers for output to numerical displays
Used in processors that perform decimal arithmetic.
Example: (9750)10 = (1001011101010000)BCD
Common Codes
2. Binary-Coded Decimal 2421( BCD 2421)
is one kind of BCD code
used to represent a decimal number
is a 4-bit binary combination with weights 2-4-2-1.
characterized by base complement

The binary combinations from 0101 to 1010 are not


included in BCD 2421
Common Codes

Example:

Number 0 has 2421 code is 0000, complements with


number 9 having 2421 code is 1111

Number 3 has 2421 code is 0011, complements with


number 6 having 2421 code is 1100
Common Codes

3. Excess 3 Code

created from 8421 code by adding 3.


has no weight.
represent a decimal digit.
characterized by base complement.
Common Codes

Example:

Number 0 has the Excess 3 code is 0011, complements


with number 9 having the Excess 3 code is 1100
Number 4 has the Excess 3 code is 0111, complements
with number 5 having the Excess 3 code is 1000
Common Codes
4. Gray Code
 is not BCD Code.
 has no weight.
created from the binary code based on the following principle:
+ MSB of Gray code and that of binary code is the same.
+ Add MSB of binary number into the right bit and write the
sum (ignore the carrier).
+ Continue to LSB.
+ The numbers of bits in Gray Code are the same to that in
binary code.
Common Codes

Example: Convert 11010 B into Gray Code.


Binary code 1 1 0 1 0

Gray code 1 0 1 1 1

The bit following bit 0 of binary code is not changed,


the bit following bit 1 of binary code is reversed
Common Codes

Example: Convert 10011 (Gray code) into binary code.

Gray code 1 0 0 1 1

Binary code 1 1 1 0 1
Common Codes
Gray code Table (4 bits)
Decimal Binary Gray
0 0000 0000
1 0001 0001 Two consecutive code
2 0010 0011 words differ in only 1 bit
3 0011 0010 (the distance between the
4 0100 0110 two code words is 1).
5 0101 0111
6 0110 0101
7 0111 0100
Common Codes
Gray code Table (4 bits)
Decimal Binary Gray
8 1000 1100
9 1001 1101 Two consecutive code
10 1010 1111 words differ in only 1 bit
11 1011 1110 (the distance between the
12 1100 1010 two code words is 1).
13 1101 1011
14 1110 1001
15 1111 1000

You might also like