0% found this document useful (0 votes)
22 views28 pages

2 Number Systems

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views28 pages

2 Number Systems

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

9/28/2023

Dinh Duc Anh Vu


International University – VNU HCM

 Number representations
 Common codes
 Computations (Digital arithmetic)

Number Systems 2

1
9/28/2023

 Recognize the basic characteristics of the binary number system.


 Convert a binary number to its decimal equivalent.
 Count in the binary number system
 Convert a number from one number system (decimal, binary,
hexadecimal) to its equivalent in one of the other number systems.
 Cite the advantages of the hexadecimal number system.
 Count in hexadecimal.
 Represent decimal numbers using the BCD code; cite the pros and cons
of using BCD.
 Understand the difference between BCD and straight binary.
 Understand the purpose of alphanumeric codes such as the ASCII code.
 Perform binary addition, subtraction, multiplication, and division on
two binary numbers.
 Compare the advantages and disadvantages among three different
systems of representing signed binary numbers.
 Manipulate signed binary numbers using the 2’s-complement system.
 Understand the BCD addition process

Number Systems 3

Decimal system
Binary system
Hexadecimal system

Number Systems 4

2
9/28/2023

453
10112
 A number in the number system is: 25.310
◦ created by one or more digits.
◦ comprised of the integer part and fractional part
separated by the radix point (or base point)
◦ Positional number system: Each digit carries a
certain weight based on its position
decimal point

… 104 103 102 101 100 . 10-1 10-2 …

tenths position
hundreds position ones position
tens position
hundredths position

Number Systems 5

 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 Systems 6

3
9/28/2023

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

Number Systems 7

 Symbol: D
 Base: 10
 Digits used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 The decimal system is a positional-value system
in which the value of a digit depends on its
position.
 Example:

2745.214=2x103+7x102+4x101+5x100
+2x10-1+1x10-2+4x10-3

Number Systems 8

4
9/28/2023

 Symbol: B
 Base: 2
 Digits used: 0, 1
 Example:
◦ 1011.101B

Number Systems 9

 Convert the number in binary system into


decimal system, i.e., calculate the value of
the binary number
 Any binary number can be converted to its
decimal equivalent simply by summing
together the weights of the various positions
in the binary number that contain a 1
 Example:

Number Systems 10

5
9/28/2023

 The first method is the reverse of the previous process:


The decimal number is simply expressed as a sum of
powers of 2, and then 1s and 0s are written in the
appropriate bit positions

 Another method for converting


decimal integers uses
repeated division by 2: divide
the integer by 2 until the quotient
is zero. Then, collect the remainders
upward
=> 19D = 10011B

Number Systems 11

 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.
 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 Systems 12

6
9/28/2023

 Example: Convert 12.69D into Binary system


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 Systems 13

 Symbol: H
 Base: 16
 Digit 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
 Calculate the value of the hexadecimal number 2A9H
2A9H = 2x162 + 10x161 + 9x160
= 2x256 + 10x16 + 9x1
= 681D
 Hexadecimal numbers are often used to describe a
computer’s memory address space
◦ 0xF000 – 0xFFFF

Number Systems 14

7
9/28/2023

 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 Systems 15

 Convert the number in


hexadecimal system into
binary system: One digit in
hexadecimal system is
equivalent to 4 bits in
binary system

3D6FH = 0011 1101 0110 1111B

Number Systems 16

8
9/28/2023

 Convert the number in binary system into


hexadecimal system: From the unit column,
group 4 bits of binary number together, then
convert each group into the corresponding
hexadecimal digit

Number Systems 17

 When converting from binary [or hex] to


decimal, use the method of taking the weighted
sum of each digit position.
 When converting from decimal to binary [or
hex], use the method of repeatedly dividing by
2 [or 16] and collecting remainders (Figure 2-1).
 When converting from binary to hex, group the
bits in groups of four, and convert each group
into the correct hex digit.
 When converting from hex to binary, convert
each digit into its four-bit equivalent.

Number Systems 18

9
9/28/2023

Code: group of special symbols that represent numbers, letters, words

Morse code: series of dots and dashes represents letters of alphabet

Straight binary coding


BCD Code
Excess-3 Code
Gray Code
Alphanumeric Code

Number Systems 19

Code word: particular combination of n bit-values that represents different numbers

Number Systems 20

10
9/28/2023

b3 b2 b1 b0
23 22 21 20

 Binary Coded Decimal (BCD 8421) 8 4 2 1


◦ 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).
0: 0000 1: 0001 2: 0010 3: 0011 4: 0100
5: 0101 6: 0110 7: 0111 8: 1000 9: 1001
 BCD Codes:
◦ Used to encode numbers for output to numerical
displays
◦ Used in processors that perform decimal arithmetic.
 Example: (9750)10 = (1001 0111 0101 0000)BCD

Number Systems 21

 Each digit of a decimal number is represented by


its binary equivalent
 Examples
8 7 4 (decimal)
↓ ↓ ↓
1000 0111 0100 (BCD)

9 4 3 (decimal)
↓ ↓ ↓
1001 0100 0011 (BCD)

Dec 0 1 2 3 4 5 6 7 8 9
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Number Systems 22

11
9/28/2023

 Convert 0110100000111001 (BCD) to its


decimal equivalent
0110 1000 0011 1001
6 8 3 9

 Convert the BCD number 011111000001 to


its decimal equivalent
0111 1100 0001
7 Error 1
(The forbidden code group indicated an error)

Number Systems 23

 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 complement of “base-1”
◦ 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
 The binary combinations from 0101 to 1010
are not included in BCD 2421

Number Systems 24

12
9/28/2023

 A straight binary code takes the complete


decimal number and represents it in binary
 A BCD code converts each decimal digit to
binary individually
 Examples
◦ 17810 = 101100102 (8 bit)
◦ 17810 = 0001 0111 1000BCD (12 bit)

 BCD uses more bits, but easier to convert to


and from decimal

Number Systems 25

 Created from 8421 code by adding 3.


 Has no weight → not suited for arithmetic
operations, but similar to BCD 8421 code
 Represent a decimal digit
 Characterized by base complement
 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

Number Systems 26

13
9/28/2023

0 1 1
1 0 0

 is not BCD Code.


 has no weight → not suited for arithmetic operations
 only one bit ever changes between two successive numbers in
the sequence
 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.

Number Systems 27

 Different:
◦ If inputs are the same, then G=0.
◦ If inputs are different, then G=1
 The bit following bit 0 of binary code is not changed, the bit following bit 1 of
binary code is reversed

Binary code 1 + 1+ 0 + 1+ 0 Gray code 1 0 0 1 1


+ + + +

Gray code 1 0 1 1 1 Binary code 1 1 1 0 1

Number Systems 28

14
9/28/2023

 Codes representing letters of the alphabet,


punctuation marks, and other special
characters as well as numbers are called
alphanumeric codes
 The most widely used alphanumeric code is
the American Standard Code for Information
Interchange (ASCII). The ASCII (pronounced
“askee”) code is a 7-bit code
 Baudot Code

Number Systems 29

“JAMES BOND 007 SAYS HI!”

Number Systems 30

15
9/28/2023

Number Systems 31

 The following is a message encoded in ASCII


code. What is the message?
◦ 1001000 1000101 1001100 1010000
◦ HELP

 Encode the following message in ASCII code


using the hex representation: “Cost=$72.”
◦ 43 6F 73 74 3D 24 37 32 2D

 The following padded ASCII-coded message is


stored in successive memory location in a
computer: 01010011 01010100 01001111
01010000. What is the message?
◦ STOP

Number Systems 32

16
9/28/2023

Representing signed numbers


Addition & Subtraction in the
2’s complement system
BCD addition

Number Systems 33

 Given number N consisting of n digits in the


base system r, complement of “base -1” of N
is defined as (rn – 1 – N).
 Example:
◦ Complement 9 of a decimal number 123D is:
103 - 1 - 123 = 999 - 123 = 876D
◦ Complement 1 of a binary number 1100B is:
24 - 1 - 12 = 15 - 12 = 3 = 0011B
◦ Complement 15 of a hexadecimal number 2CH is:
162 - 1 - 44 = 255 - 44 = 211 = D3H

Number Systems 34

17
9/28/2023

 To find complement 9 of a decimal number,


take 9 minus each digit
 Example: Find complement 9 of 270284D
9 9 9 9 9 9
2 7 0 2 8 4
7 2 9 7 1 5
Result: Complement 9 of 270284 is 729715

Number Systems 35

 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
◦ Complement 1 of 01101110B is 10010001B

Number Systems 36

18
9/28/2023

 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 a decimal number 123D is:
103 - 123 = 1000 - 123 = 877D
◦ Complement 2 of a binary number 1100B is:
24 - 12 = 16 - 12 = 4 = 0100B
◦ Complement 16 of a hexadecimal number 2CH is:
162 - 44 = 256 - 44 = 212 = D4H
Number Systems 37

 Base complement can also 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

Number Systems 38

19
9/28/2023

 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.
◦ Example:
 1010B = 10D, in range of 0 to 24 – 1 (15)
 01100001B = 97D, in range of 0 to 28 – 1 (255)

Number Systems 39

 Signed binary number


◦ Three ways to represent signed numbers
1. Sign-Magnitude
2. 1’s Complement
3. 2’s Complement

Number Systems 40

20
9/28/2023

+98
-67
+123.7
-13.72

 A number consists of a magnitude and a symbol


indicating whether the magnitude is positive or
negative
 For binary system
◦ MSB is used as the sign bit (0 – plus, 1 – minus)
◦ The magnitude bits are the true binary equivalent of the
decimal value being represented

◦ Two values for zero: 0000 and 1111


◦ Range for n bits:
-(2n-1-1) through +(2n-1-1)

Number Systems 41

 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:

 Two values for zero: 0000 and 1111


 Range for n bits: -(2n-1-1) through +(2n-1-1)

Number Systems 42

21
9/28/2023

 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
2′𝑠 𝑐𝑜𝑚𝑝𝑙𝑒𝑚𝑒𝑛𝑡
1010𝐵 −6𝐷
 Only one representation of zero
 Range for n bits: -2n-1 through +(2n-1-1)

Number Systems 43

 Represent -9D in 2’s complement form


◦ +9D = 01001B
◦ 2’s complement of 01001B is 10111B
◦ So -9D = 10111B

 Convert -14D into signed binary number


◦ +14D = 01110B
◦ Complement 2 of 01110B is 10010B
 -14D = 10010B

 Convert the signed binary number 11101B into


Decimal number
◦ Complement 2 of 11101B is 00011B = +3D
 11101B = -3D

Number Systems 44

22
9/28/2023

 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.
 Copy sign bit to the left is called sign extension
 Example:
◦ 0110B = 00110B = 000110B = … = +6D
◦ 1010B = 11010B = 111010B = … = -6D

Number Systems 45

 Another way 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
 To negate a signed binary number by 2’s-
complementing it

Number Systems 46

23
9/28/2023

Number Systems 47

 Example: 7 + 6

 Overflow if result out of range


◦ Adding +ve and –ve operands, no overflow
◦ Adding two +ve operands
 Overflow if result sign is 1
◦ Adding two –ve operands
 Overflow if result sign is 0

Number Systems 48

24
9/28/2023

 Negate the subtrahend and add this to the


minuend
 Example: 9 – 4 = 9 + (–4)

 Overflow if result out of range


◦ Subtracting two +ve or two –ve operands, no overflow
◦ Subtracting +ve from –ve operand
 Overflow if result sign is 0
◦ Subtracting –ve from +ve operand
 Overflow if result sign is 1

Number Systems 49

Example: Using 2’s complement to do the subtraction


111001 - 1010
111001
+
Complement 2 of 001010 is: 110110

1101111
Ignore the last carry:
111001 - 1010 = 101111

Number Systems 50

25
9/28/2023

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 2’s complement of 010001
is 101111  1010 - 111001 = -101111

Number Systems 51

Number Systems 52

26
9/28/2023

 Sum Equals 9 or Less


◦ none of the sums of the pairs of decimal digits exceeded 9;
therefore, no decimal carries were produced.
◦ the BCD addition process is straightforward and is actually
the same as binary addition
 Sum Greater than 9
◦ Sum is one of the six forbidden or invalid four-bit code
groups because the sum of the two digits exceeds 9.
◦ Whenever this occurs, the sum must be corrected by the
addition of six (0110) to take into account the skipping of
the six invalid code groups

Number Systems 53

 Using ordinary binary addition, add the BCD code


groups for each digit position.
 For those positions where the sum is 9 or less, no
correction is needed. The sum is in proper BCD
form.
 When the sum of two digits is greater than 9, a
correction of 0110 should be added to that sum to
get the proper BCD result. This case always
produces a carry into the next digit position, either
from the original addition (step 1) or from the
correction addition

Number Systems 54

27
9/28/2023

 The hexadecimal number system is used in digital systems


and computers as efficient ways of representing binary
quantities
 In conversion between hex and binary, each hex digit
corresponds to 4 bits
 The repeated division method is used to convert decimal
numbers to binary or hexadecimal
 Using N bit binary number, we can represent decimal
values from 0 to 2N-1
 The BCD code for a decimal number is formed by
converting each digit of the decimal number to its 4-bit
binary equivalent
 An alphanumeric code is one that uses groups of bits to
represent all of the various characters and functions that
are part of a typical computer’s keyboard. The ASCII code
the most widely used alphanumeric code

Number Systems 55

28

You might also like