02 Binary Codes
02 Binary Codes
Binary Codes
BINARY-CODED DECIMAL (BCD)
Binary Codes
BINARY-CODED DECIMAL (BCD)
Binary Codes
BINARY-CODED DECIMAL (BCD)
• The Binary Coded Decimal (BCD) code is used for
representing the decimal digits 0 through 9.
• BCD uses four bits, with the weights equal to those of a 4-bit
binary integer (BCD)
Binary Codes
BINARY-CODED DECIMAL (BCD)
5 8
0101 1000
Binary Codes
BINARY-CODED DECIMAL (BCD)
• For example, convert 17410 into its BCD form:
1 7 4
Binary Codes
BINARY-CODED DECIMAL (BCD)
3 6 2 . 5 7
362.5710 = 001101100010.01010111BCD
Binary Codes
BINARY-CODED DECIMAL (BCD)
00 01 1001 0101
1 9 5
Binary Codes
BINARY-CODED DECIMAL (BCD)
Binary Codes
BCD ADDITION
Examples:
Binary Codes
BCD ADDITION
Example:
410 = 0100BCD
+ 610 = 0110
0011BCD
1010 = 1010
0111BCD
BCD
Binary Codes
BCD ADDITION
Example:
810 = 0100
1000BCD
BCD
+ 910 = 0011
1001BCD
BCD
1710 =10111
0001BCD
BCD
0001 0111BCD
1110
Binary Codes
BCD ADDITION
Examples:
410 = 0100BCD 810 = 0000
1000
BCDBCD
+ 610 = 0110
0011BCD + 910 = 0011
1001
BCDBCD
1010 = 1010
0111BCD
BCD 1710 = 10111
0001BCD
BCD
+ 0110BCD + 0110BCD
1 0000BCD 1 0111BCD
1010 1710
Binary Codes
EXERCISES
1. 6210
2. 2510
3. 27410
4. 28410
5. 42.9110
6. 5.01410
Binary Codes
EXERCISES
1. 1001BDC
2. 101BCD
3. 1100001BCD
4. 1000111BCD
5. 110110.1000BCD
6. 111000.10001BCD
Binary Codes
GRAY CODES
Binary Codes
GRAY CODES
• If binary numbers are used, a Decimal Binary Gray Code
0 0000 0000
change, for example, from 0111 1 0001 0001
to 1000 may produce an 2 0010 0011
intermediate erroneous number 3 0011 0010
1001 if the value of the rightmost 4 0100 0110
bit takes longer to change than do 5 0101 0111
the values of the other three bits . 6 0110 0101
7 0111 0100
8 1000 1100
0 1 1 1 9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
1 0 0 1 14
15
1110
1111
1001
1100
Binary Codes
GRAY CODES
Decimal Binary Gray Code
• The Gray code eliminates this 0 0000 0000
0 1 0 1 13
14
1101
1110
1011
1001
15 1111 1100
Binary Codes
CONVERTING BINARY TO GRAY CODE
• Write the binary number completely.
9310 = 10111012
• Add the most significant bit to the next significant bit of the binary number. Disregard any carry
terms.
1 0 1 1 1 0 1
+
1 1
• Add the second significant bit to third significant bit, also disregard the carry, and so forth up to
the least significant bit.
1 0 1 1 1 0 1
+ + + + +
1 1 1 0 0 1 1
Binary Codes
CONVERTING GRAY CODE TO BINARY
1110011GC
• Add the MSB of the binary number to the Gray code number in the next significant bit,
neglecting the carry terms that result.
1 1 1 0 0 1 1
+
1 01
• Continue step 3 until all Gray code bits have been used
1 1 1 0 0 1 1
+ + + + +
1 0 1 1 1 0 1
Binary Codes
GRAY CODES
• Exercises • Exercises
110101012 11010101GC
8F16 11110000GC
23410 01010101GC
Binary Codes
ASCII CODE
Binary Codes
ASCII CODE
• An alphanumeric character set is a set of elements that includes the 10 decimal
digits. the 26 letters of the alphabet. and a number of special characters .
• Such a set contains between 64 and 128 elements if both uppercase and
lowercase letters are included.
• The standard binary code for the alphanumeric characters is the American
Standard Code for Information Interchange (ASCII ), which uses seven bits to
code 128 characters.
• The ASCII code also contains 94 graphic characters that can be printed and 34
non printing characters used for various control functions.
• The graphic characters consist of the 26 uppercase letters (A through Z). the 26
lowercase letters (a through z), the 10 numerals (0 through 9), and 32 special
printable characters, such as %, *, and $.
Binary Codes
ASCII CODE
A = 4116 = 010000012
Binary Codes
ASCII CODE
1. format effectors
2. information separators
3. communication-control
characters.
Binary Codes
EXCESS-K REPRESENTATION
Unsigned Binary Decimal
• In unsigned binary using 4 bits, 0000 0
00002 is equivalent to 010 (the 0001 1
smallest unsigned integer) lowest 0010 2
while 11112 is equivalent to 0011 3
1510 (the highest unsigned 0100 4
integer that can be represented 0101 5
using 4 bits) 0110 6
0111 7
• Usually there is some hardware 1000 8
that could sort unsigned 1001 9
numbers, or at the very least, 1010 10
compare two unsigned integers 1011 11
and determine which number highest 1100 12
was larger, or if they were 1101 13
equal.
1110 14
1111 15
Binary Codes
EXCESS-K REPRESENTATION
2's C Binary Decimal
• Now recall the 2's complement 0000 0
representation. 0001 +1
0010 +2
• The one disadvantage of 2's complement is 0011 +3
that the numbers cannot be sorted.
0100 +4
highest
0101 +5
• The hardware that can sort or compare
unsigned numbers could not be used for 0110 +6
numbers in 2's complement. In particular, it 0111 +7
would say all negative values were larger 1000 -8
than non-negative values.
1001 -7
lowest 1010 -6
• This leads to another idea for signed number
representation in which the same ordering 1011 -5
where 0000 represents the smallest value 1100 -4
and 1111 represents the largest value is 1101 -3
kept.
1110 -2
1111 -1
Binary Codes
EXCESS-K REPRESENTATION
Binary Codes
EXCESS-K REPRESENTATION
Decimal Excess-8
-8 0000
Binary Codes
EXCESS-K REPRESENTATION
Decimal Excess-8 2's C Binary
-8 0000 1000
-7 0001 1001
-6 0010 1010
-5 0011 1011
-4 0100 1100
• In general, the effect is -3 0101 1101
conveniently the same as -2 0110 1110
using two's complement -1 0111 1111
except that the most 0 1000 0000
significant bit is inverted. +1 1001 0001
+2 1010 0010
+3 1011 0011
+4 1100 0100
+5 1101 0101
+6 1110 0110
+7 1111 0111
Binary Codes
EXCESS-K REPRESENTATION
Binary Codes
EXCESS-K REPRESENTATION
Binary Codes
EXCESS-K REPRESENTATION
Examples:
-5 + 8 = 3 = 00112
Binary Codes
EXCESS-K REPRESENTATION
Examples:
110001112 = 199
199 – 128 ==+71
+71
00112 ==33
3 – 4 = =– –1 1
Binary Codes
EXCESS-K REPRESENTATION
• Exercises
10002 excess-7
100000012 excess-127
Binary Codes
FLOATING-POINT NUMBERS
b7 b6 b5 b4 b3 b2 b1 b0 .
Binary Codes
FLOATING-POINT NUMBERS
2(n-1) to +2 (n-1) − 1
−231 to +231 − 1
Binary Codes
FLOATING-POINT NUMBERS
b31 b30 b29 b28 b27 . . . b2 b1 b0 .
• It is also possible to assume that the binary point is just to
the right of the sign bit, thus representing a fraction.
• In this case, the binary point is said to float, and the numbers are
called floating-point numbers.
Floating Point:
.
The point moves left or right according to an exponent value.
BInary Codes
FLOATING-POINT NUMBERS
• In the decimal scientific notation, numbers may be written
as 6.0246 x 1023, 6.6254 x 10-27, −1.0341 x 102, −7.3000 x
10-14, and so on.
Binary Codes
FLOATING-POINT NUMBERS
N = S × rE
Binary Codes
FLOATING-POINT NUMBERS
55.66 × 100
5.566 × 101 The exponent increases if
the decimal point is
0.5566 × 102 moved to the left and
556.6 × 10-1 vice-versa.
10110.110 × 20
10.110110 × 23
1011011.0 × 2-2
Binary Codes
FLOATING-POINT NUMBERS
Binary Codes
FLOATING-POINT NUMBERS
• For example:
1010.1011 × 22 ×= 21.0101011
3. × 25
Binary Codes
FLOATING-POINT NUMBERS
Binary Codes
FLOATING-POINT NUMBERS
a) The most significant bit is the sign bit (S), with 0 for positive numbers
and 1 for negative numbers.
b) The following 8 bits represent exponent (E) using the excess-127
format.
c) The remaining 23 bits represents the fraction (F). The actual significand
is normalized with an implicit leading 1 in the form of 1.F.
Binary Codes
FLOATING-POINT NUMBERS
Binary Codes
FLOATING-POINT NUMBERS
• However, the end values
of E', namely, 0 and 255, Exponent Exponent in Actual Exponent
are not used to represent (Binary) Decimal (E') (E)
exponents. 00000000 0 number
-127 is 0
00000001 1 -126
Instead, these are used to 00000010 2 -125
indicate floating-point . . .
values of exact 0 and . . .
infinity, respectively.
. . .
01111111 127 0
• This means that the
actual exponent, E, is in 10000000 128 +1
the range –126 ≤ E ≤ 127. 10000001 129 +2
. . .
• The excess–k . . .
representation for . . .
exponents enables 11111101 253 +126
efficient comparison of 11111110 254 +127
the relative sizes of two 11111111 255 number
+128 is ∞
floating-point numbers.
Binary Codes
FLOATING-POINT NUMBERS
S=1
E = 10000001
F = 01100000000000000000000
1.01100000000000000000000
Binary Codes
FLOATING-POINT NUMBERS
Since S = 1, this represents a negative number.
– 1.01100000000000000000000 × 22 ==––101.1
101.1
– (1 × 22 + 0 × 21 + 1 × 20 + 1 × 2-1) = – 5.510.
Binary Codes
FLOATING-POINT NUMBERS
S=0
E = 10000100
F = 00010111001000000000000
1.00010111001000000000000
Binary Codes
FLOATING-POINT NUMBERS
+ 1.00010111001000000000000 × 25 = + 100010.111001
Binary Codes
FLOATING-POINT NUMBERS
• To convert the decimal number 0.101562510 to the 32-bit floating-
point binary representation.
0.101562510 = 0.00011012
Binary Codes
FLOATING-POINT NUMBERS
Binary Codes
FLOATING-POINT NUMBERS
• Exercises
110000101010110010000000000000002
BF40000016
10.62510
–0.7510
Binary Codes
FLOATING-POINT NUMBERS
a) The most significant bit is the sign bit (S), with 0 for positive numbers
and 1 for negative numbers.
b) The following 11 bits represent exponent (E) using the excess-1023
format.
c) The remaining 52 bits represents the fraction (F). The actual significand
is normalized with an implicit leading 1 in the form of 1.F.
Binary Codes