Lec05 Number Systems Binary Codes
Lec05 Number Systems Binary Codes
16/01/2024 EE213M 1
Signed binary Numbers
• In conventional arithmetic, a negative number is indicated by a “-” sign and a positive number by a “+”
sign.
• In Binary number system a sign bit is used.
• Sign bit is 0 for positive numbers and 1 for negative numbers.
• For unsigned binary numbers (11001)2= (25)10
• For signed binary numbers (11001)2= (-9)10
• This method of representing negative numbers is called as signed-magnitude convention.
• Other method of representing negative numbers using complements is called as signed-complement
conventions
16/01/2024 EE213M 2
Numbers Signed Magnitude Signed 1’s complement Signed 2’s complement
Convention representation representation
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
16/01/2024 EE213M 3
Addition of signed numbers using 2’s Complement
convention
• It is performed addition of the two numbers, including their sign bits.
• A carry out of the sign‐bit position is discarded.
16/01/2024 EE213M 4
Addition of signed numbers using 2’s Complement
convention
• Overflow Condition
• When the number of bits assigned is not enough to accommodate the sum.
16/01/2024 EE213M 5
Subtraction of signed numbers using 2’s Complement
convention
• Subtractions of signed numbers is same process as addition.
• M – N = M + (-N)
• binary numbers in the signed‐complement system are added and subtracted by the same basic addition
and subtraction rules as unsigned numbers.
• common hardware circuit can handle both types of arithmetic.
• signed‐complement system are mostly used in all arithmetic units of computer systems.
• The user or programmer should have the knowledge that numbers are signed or unsigned
16/01/2024 EE213M 6
Binary Codes
• Information in a digital computer is usually coded rather than binary numbers.
• It is because humans are comfortable in decimal systems and input and output information are mostly in
decimal numbers.
16/01/2024 EE213M 7
BCD Code
• In BCD Code, Each decimal number is coded by a string of 4 bits.
Decimal BCD Code
• A string of 4 bits can have maximum 16 possible combinations, so 6 combinations Number
from 1010 to 1111 remain unassigned in BCD code. 0 0000
( 123.45)10 = 0001 0010 0011. 0100 0101 1 0001
2 0010
BCD require more or equal to number of bits to represent a decimal number as 3 0011
Compared to binary numbers. 4 0100
5 0101
6 0110
• BCD numbers are decimal numbers and not binary numbers, although they use
bits in their representation 7 0111
8 1000
9 1001
16/01/2024 EE213M 8
BCD Addition
• When the binary sum is equal to or less than 1001 (without a carry), the corresponding BCD digit is
correct. However,
• when the binary sum is greater than or equal to 1010, the result is an invalid BCD digit.
• The addition of 6 = (0110)2 to the binary sum converts it to the correct digit.
4 0100 184 0001 1000 0100
5 0101 520 0101 0010 0000
9 1101 704 0110 1010 0100
1 0110
4 0100
0111 0000 0100
8 1000
12 1100
Add 6 0110
10010
16/01/2024 EE213M 9
Weighted Codes (2421 and 6311 code)
Decimal BCD Code 2421 Code 6311 Code
Number 8421 code
• Similar to BCD code, Each decimal number is
represented by 4 bits. 0 0000 0000 0000
• Each position from MSB to LSB is having certain 1 0001 0001 0001
weights. that’s why called as weighted codes. 2 0010 0010 0011
• 2421 codes have the weights of 2,4,2,1 consecutively 3 0011 0011 0100
from MSB to LSB. 4 0100 0100 0101
• 6311 code will have the weights of 6,3,1,1 5 0101 1011 0111
consecutively from MSB to LSB.
6 0110 1100 1000
7 0111 1101 1001
• Some digits Can be coded by two different ways in 8 1000 1110 1011
2421 code and 6311 code.
9 1001 1111 1100
16/01/2024 EE213M 10
Excess-3 Code
• Excess‐3 is an unweighted code. Decimal BCD Code Excess-3
Number 8421 code
• Each coded combination is obtained from the corresponding binary
value plus 3. 0 0000 0011
1 0001 0100
16/01/2024 EE213M 11
Decimal Binary Gray
Number Number Code
Gray Code 0 0000 0000
1 0001 0001
• It is convenient to use the Gray code to represent digital data that have been
2 0010 0011
converted from analog data.
3 0011 0010
• The advantage of the Gray code is that only one bit in the code group changes in
going from one number to the next. 4 0100 0110
• It is used in applications where hardware may produce an error during transition from 5 0101 0111
one number to next. 6 0110 0101
7 0111 0100
• Conversion from binary number to Gray Code 8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
16/01/2024 EE213M 12
ASCII Character Code
• American Standard Code for Information
Interchange (ASCII)
• Standard binary code for the alphanumeric
characters.
• It uses seven bits to code 128 characters.
• The seven bits of the code are designated by b1
through b7, with b7 the most significant bit.
• A= 1000001
16/01/2024 EE213M 13
Error-Detecting Code
• An Extra bit is used which is 0 or 1 depending upon the number of 1’s in the remaining bits.
• It is called as parity bit.
• This parity bit is added in MSB position to make the total number of 1’s in the character to be even for even parity and
odd for odd parity.
16/01/2024 EE213M 14
Problem sets
• Q. 1 Add the following numbers in binary using 2’s complement.
(i) 18 + (-25) (ii) (-11) + (-21)
16/01/2024 EE213M 15