You are on page 1of 33

E1121 Digital LOGIC (a)

Fall 2020

Lecture 3
Number System
Signed / Unsigned Numbers
01
Agenda
Arithmetic Operations on
Signed Numbers 02

Binary Code
03

BCD Addition
04
Signed / Unsigned
Numbers
Signed/Unsigned
AgendaNumbers
Style
• Positive integers (including zero) can be represented as unsigned numbers.
• we need a notation to represent negative integers.
– In ordinary arithmetic, a minus sign indicates a negative number and plus sign
indicates a positive number.

• computers must represent everything with binary digits due to hardware


limitations.
• The sign is represented by an extra bit placed in the leftmost position of the
number.
– The sign bit 0 for positive and 1 for negative.
Signed/Unsigned
AgendaNumbers
Style
• Both signed and unsigned binary numbers consist of a string of bits.

• The user determines whether the number is signed or unsigned.

• If the binary number is signed, then the sign is indicated by the leftmost
bit and the reminder of the bits indicates the number value (magnitude).

• If it is assumed that the binary number is unsigned, then the leftmost bit is
the most significant bit of the number. (part of the number value)

• For example,
Number Unsigned signed
01001 9 +9
11001 25 -9
One Signed/Unsigned
Agenda Style Numbers

• How do we write negative binary numbers?


– Prefix numbers with minus symbol?

• 3 approaches:
– Sign and magnitude negates a number by changing its sign
– r’s-complement negates a number by taking its r’s complement
– (r-1)’s-complement negates a number by taking its (r-1)’s comp
• All 3 approaches represent positive numbers in the same way
Sign andAgenda
magnitudeStyle

–7 +0
• Most significant bit (MSB) is the sign bit –6 1111 0000 +1

–5 1110 0001 +2
– 0 ≡ positive 1101 0010
–4 +3
1100 0011
– 1 ≡ negative
– 3 1011 0100 + 4
1010 0101
–2 1001 0110 +5

–1 1000 0111 +6
• Remaining bits are the number's magnitude
–0 +7
One’s-complement
Agenda Style
• Negative number: one’s complement of –0 +0
–1 1111 0000 +1
positive number 1110 0001
–2 +2
1101 0010
– 0111 ≡ 710 –3 +3
1100 0011

– 1000 ≡ –710 – 4 1011 0100 + 4


1010 0101
–5 1001 0110 +5

–6 1000 0111 +6
–7 +7
Two’s-complement
Agenda Style
• Negative number: two’s complement of the
positive number –1 0
–2 1111 0000 +1
– 0111 ≡ 710 1110 0001
–3 +2
1101 0010
– 1001 ≡ –710 –4 +3
1100 0011

• Benefits: – 5 1011 0100 + 4


1010 0101
–6 1001 0110 +5
– Simplifies arithmetic
–7 1000 0111 +6
– Only one zero! –8 +7
Arithmetic Operations on
Signed Numbers
Arithmetic Operations
Agenda on Signed Numbers
Style
❑ Convert the decimal number to binary then use the signed 2’s complement
representation to perform the following operations

(+4) + (+2) (-4) + (-2)

0100 1100
0010 1110
0110 = (+6) 11010 = (-6)
no overflow no overflow
no carry carry
the result is correct Ignoring the carry, the result is
correct
ArithmeticAgenda
OperationsStyle
on Signed Numbers (cont.)

❑ Convert the decimal number to binary then use the signed 2’s complement
representation to perform the following operations

(+4) + (+6) (-4) + (-6)


0100 1100
0110 1010
1010 = (-6) 10110 = (+6)
overflow overflow
no carry carry
the result is incorrect Ignoring the carry, the result is
incorrect
ArithmeticAgenda
OperationsStyle
on Signed Numbers (cont.)

 In order to get an accurate answer, we must ensure that the result has
enough bits to accommodate the sum .

 If we have two n‐bit numbers and the sum occupies n + 1 bits, then
an overflow occurs.
(+4) + (+6) (-4) + (-6)

00100 11100
00110 11010
01010 = (10) 110110 = (-10)
Binary Code
Binary Code
Agenda Style
• A binary code is just an assignment of information to bit patterns.

• What are the required number of bits to represent 2n distinct elements


in a binary code ?
• requires a minimum of n bits.

• There is no maximum number of bits that may be used for a binary code.

• For example number 9 can be represented by using minimum 4 bit as


1001
Binary codes types:

Alphanumeric Weighted codes Non_ Weighted


codes BCD(8421)
codes
EBCDIC Excess-3
2421
ASCII Gray
6311

642-3

84-2-1
Binary-Coded Decimal
Agenda (BCD)
Style
• BCD is a weighted code as each decimal digit can be obtained by adding the

fixed weights which assign to the code.

• The weights for the BCD bits are 8, 4, 2, 1 that why the code sometimes

known as the 8421 code.

• Would it be easy for you if you can replace a decimal number with an

individual binary code?

– Such as 00011001 = 1910


Binary Coded Decimal
Agenda Style
Decimal
0 1 2 3 4 5 6 7 8 9
Digit
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!

ex1: decimal-to-BCD ex2: BCD-to-decimal


(a) 35 (a) 10000110
(b) 98 (b) 001101010001
(c) 170 (c) 1001010001110000
(d) 2469
2421 code
Agenda Style
• This is a weighted code with weight 2, 4, 2, and 1

• This code is self-complementing, that is, the code word for the 9s’
complement of any decimal digit is equivalent to the one’s
complement of the binary code of that decimal digit.

Decimal 9’s comple 2421 code 1’s comple 2421 code


ment of decimal ment of 9’s comp
digit lement
2 7 0010 1101 1101
3 6 0011 1100 1100
Excess-3Agenda
code Style
• This code is also self-complementing like 2421 code.

• while this code is not weighted, there is an arithmetic relationship


between the BCD code and Excess-3 code.

• The code word for each decimal digit is the corresponding BCD code
word plus 00112.
0010 = 2 in BCD
+ 00112
= 0101 = 2 in excess-3
Binary Codes for Decimal
Agenda StyleNumbers
• It is necessary to note that this
table introduces binary codes
and not binary numbers.
• A binary number is
mathematically defined, while
a binary code is just an
assignment of numeric values
to bit patterns
The GrayAgenda
Code Style
❑ Binary-to-Gray code conversion
✓ The MSB of Gray code and MSB of binary number are the same.
✓ Preceding from left to right, add the two adjacent binary bits to obtain the
next Gray code bit. Neglect carries.

ex: convert 101102 to Gray code


1 + 0 + 1 + 1 + 0 binary

1 1 1 0 1 Gray
Gray Code
Agenda Style
• Note that Gray code is a code
where only one-bit changes at
a time while moving from
number to next number in
sequence.
ASCII Code
Agenda Style
• The most commonly used for representing character code is ASCII
(the American Standard Code for Information Interchange).

• ASCII represents each character with a 7-bit string, making a total of


128 characters.

• The code contains the uppercase and lowercase alphabet, numeral,


punctuation, and various nonprinting control characters.
ASCII Code
Agenda Style
ExampleAgenda Style
 Convert the decimal 8657 to BCD, 2421, excess-3, 84-2-1and ASCII
1. Decimal 8 6 5 7
2. BCD 1000 0110 0101 0111
3. 2421 1110 1100 1011 1101
4. Excess-3 1011 1001 1000 1010
5. 84-2-1 1000 1010 1011 1001
6. ASCII 0111000 0110110 0110101 0110111
ExampleAgenda Style
 What is 011010011000 content if it represent BCD, 2421, excess-3
1. BCD 698
2. 2421 not vaild
3. Excess-3 365
4. 84-2-1 278
5. Binary 8+16+128+512+1024= 1688
Codes for detecting Style
Agenda and correcting errors

• An error in a digital system is the corruption of data from its correct value to
some other value.
– i.e., a change of some bits from 1 to 0 or vice versa.

• During the processing or transmission of digital data a noise may modify


some bits from 0 to 1 or vice versa.

• A short duration noise can affect only a single bit causes a single-bit error.

• A long duration noise can affect two or more bits causes a multi-bit error.
Parity check
Agenda Style
• One of the most common ways to detect error is using a parity bit.
• A parity bit is an additional bit used with a message to make the total number
of 1’s transmitted either odd or even.
• If an even parity is used, the P bit is chosen such that the total number of 1’s is
even.
BCD Addition
BCD Addition
Agenda Style
• Steps to add two BCD numbers:
– Add the two BCD numbers, using the rules for basic binary addition.
– If a 4-bit sum of each pair digits is equal to or less than 9, it is a valid B
CD number.
– If a 4-bit sum > 9, or if a carry out of the 4-bit group is generated it is a
n invalid result.
• Add 6 (0110) to a 4-bit sum to skip the six the invalid states and return the
code to 8421. If a carry results when 6 is added, simply add the carry to the
next 4-bit group.
BCD Addition
Agenda Style
Decimal BCD Equivalent
10
234 0010 0011 0100
185 0001 1000 0101
419 0100 1011 1001
0110
0100 0001 1001
Thank you

You might also like