Professional Documents
Culture Documents
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.
• 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
• 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
–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
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
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.
• There is no maximum number of bits that may be used for a binary code.
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
• The weights for the BCD bits are 8, 4, 2, 1 that why the code sometimes
• Would it be easy for you if you can replace a decimal number with an
Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!
• 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.
• 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.
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).
• 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.
• 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