Unit-1 DLD
Unit-1 DLD
Binary codes
Boolean algebra
8 + 4+ 0+ 1+ 0 + 0.25 = 13.25
(1101.01)2 = (13.25)10
162 / 2 = 81 rem 0
81 / 2 = 40 rem 1 0.375 x 2 = 0.750
40 / 2 = 20 rem 0 0.750 x 2 = 1.500
20 / 2 = 10 rem 0 0.500 x 2 = 1.000
10 / 2 =5 rem 0
5/2 =2 rem 1
2/2 =1 rem 0
1/2 =0 rem 1
• Each division strips off the rightmost digit (the remainder). The
quotient represents the remaining digits in the number
• Similarly, to convert fractions, each multiplication strips off the
leftmost digit (the integer part). The fraction represents the
remaining digits
• Converting from binary to octal: Make groups of 3 bits, starting from the
binary point. Add 0s to the ends of the number if needed. Convert each bit
group to its corresponding octal digit.
1 0 1 1 0 0 0
+0 1 O 0 1 1 1
1 1 1 1 1 1 1
16
Unit-I Number system and Boolean Algebra
Radix Complement
The r's complement of an n-digit number N in base r is defined as
rn – N for N ≠ 0 and as 0 for N = 0. Comparing with the (r 1) 's
complement, we note that the r's complement is obtained by adding
1 to the (r 1) 's complement, since rn – N = [(rn 1) – N] + 1.
• Example: Base-10
The 10's complement of 012398 is 987602
The 10's complement of 246700 is 753300
• Example: Base-2
The 2's complement of 1101100 is 0010100
The 2's complement of 0110111 is 1001001
17
Unit-I Number system and Boolean Algebra
2’s Co Radix Complement
– Take 1’s complement then add 1
OR – Toggle all bits to the left of the first ‘1’ from the
right
Example:
Number: 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 0
1’s Comp.:
0 1 0 0 1 1 1 1
+
1 0 10 1 0 0 0 0
0 1 0 1 0 0 0 0
18
Unit-I Number system and Boolean Algebra
Applications
• Subtraction with Complements
– The subtraction of two n-digit unsigned numbers
M – N in base r can be done as follows:
19
Unit-I Number system and Boolean Algebra
Complements
• Example
– Using 10's complement, subtract 72532 – 3250.
22
Unit-I Number system and Boolean Algebra
10’s Complement Examples
Example #1:
-003
Complement Digits
996
+1 Add 1
997
Example #2
: -214
Complement Digits
785
+1 Add 1
786
Unit-I Number system and Boolean Algebra 23
2’s Complement Examples
Example #1
5 = 00000101
Complement Digits
11111010
+1
Add 1
-5 = 11111011
Example #2
-13 = 11110011
Complement Digits
00001100
+1
Add 1
13 = 00001101 24
2’s Complement Examples
Example #1
5 = 00000101
Complement Digits
11111010
+1
Add 1
-5 = 11111011
Example #2
-13 = 11110011
Complement Digits
00001100
+1
Add 1
13 = 00001101 25
Using The 2’s Complement Process
Use the 2’s complement process to add together
the following numbers.
27
POS + NEG → POS Answer
Take the 2’s complement of the negative number and
use regular binary addition.
9 00001001
+ (-5) + 11111011
4 1]00000100
8th Bit = 0: Answer is Positive
Disregard 9th Bit
00000101
2’s
11111010 Complement
Process
+1
11111011 28
POS + NEG → NEG Answer
Take the 2’s complement of the negative number and
use regular binary addition.
(-9) 11110111
+ 5 + 00000101
-4 11111100
8th Bit = 1: Answer is Negative
11111100 00001001
To Check: 2’s
Perform 2’s
Complement
00000011 11110110 Complement
Process
On Answer +1 +1
00000100 11110111 29
NEG + NEG → NEG Answer
Take the 2’s complement of both negative numbers
and use regular binary addition.
2’s Complement
(-9) 11110111 Numbers, See
Conversion Process
-14 1]11110010
8th Bit = 1: Answer is Negative
Disregard 9th Bit
11110010
To Check:
Perform 2’s
Complement
00001101
On Answer +1
00001110 30
Signed Binary Numbers
To represent negative integers, we need a notation
for negative values.
It is customary to represent the sign with a bit
placed in the leftmost position of the number
since binary digits.
The convention is to make the sign bit 0 for
positive and 1 for negative.
Example:
32
Unit-I Number system and Boolean Algebra
Signed Binary Numbers
• Arithmetic addition
– The addition of two numbers in the signed-magnitude system follows the
rules of ordinary arithmetic.
– If the signs are the same,we add the two magnitudes and give the sum
the common sign.
– If the signs are different, we subtract the smaller magnitude from the larger
and give the difference the sign if the larger magnitude.
– The addition of two signed binary numbers with negative numbers
represented in signed-2's-complement form is obtained from the addition
of the two numbers, including their sign bits.
– A carry out of the sign-bit position is discarded.
33
Unit-I Number system and Boolean Algebra
Example :
Examples
( A) ( B ) ( A) ( B )
( A) ( B ) ( A) ( B )
(11111010 11110011)
( 6) ( 13)
• Example: (11111010 + 00001101)
00000111 (+ 7)
35
Unit-I Number system and Boolean Algebra
Binary Codes
BCD Code
◦ A number with k decimal digits will
require 4k bits in BCD.
◦ Decimal 396 is represented in BCD
with 12bits as 0011 1001 0110,
with each group of 4 bits
representing one decimal digit.
◦ A decimal number in BCD is the
same as its equivalent binary
number only when the number is
between 0 and 9.
◦ The binary combinations 1010
through 1111 are not used and
have no meaning in BCD.
36
Unit-I Number system and Boolean Algebra
Binary Code
• Example:
– Consider decimal 185 and its corresponding value
in BCD and binary:
• BCD addition
37
Unit-I Number system and Boolean Algebra
Binary Code
• Example:
– Consider the addition of 184 + 576 = 760 in BCD:
38
Unit-I Number system and Boolean Algebra
Binary Codes
• Other Decimal Codes
39
Unit-I Number system and Boolean Algebra
Binary Codes
• Gray Code
– The advantage is that
only bit in the code
group changes in going
from one number to the
next.
000
• Error detection. 001
• Representation of analog data.
• Low power design.
010 011
100 101
110 111
40
Unit-I Number system and Boolean Algebra
Binary Codes
• American Standard Code for Information Interchange (ASCII) Character
Code
41
Unit-I Number system and Boolean Algebra
Binary Codes
• ASCII Character Code
42
Unit-I Number system and Boolean Algebra
ASCII Character Codes
American Standard Code for Information Interchange
A popular code used to represent information sent as
character-based data.
It uses 7-bits to represent:
◦ 94 Graphic printing characters.
◦ 34 Non-printing characters.
Some non-printing characters are used for text format
(e.g. BS = Backspace, CR = carriage return).
Other non-printing characters are used for record
marking and flow control
(e.g. STX and ETX start and end text areas).
43
Unit-I Number system and Boolean Algebra
Boolean Algebra
• Boolean Constants
– these are ‘0’ (false) and ‘1’ (true)
– Boolean Variables
– variables that can only take the vales ‘0’ or ‘1’
• Boolean Functions
– each of the logic functions (such as AND, OR and
NOT) are represented by symbols as described
above
– Boolean Theorems
– a set of identities and laws – see text for details
44
Unit-I Number system and Boolean Algebra
Boolean identities
00=0 0+0=0 0 1
01=0 0+1=1 1 0
10=0 1+0=1 A A
11=1 1+1=1
A0=0 A+0=A
0A=0 0+A=A
A1=A A+1=1
1A=A 1+A=1
AA=A A+A=A
A A 0 A A 1
45
Unit-I Number system and Boolean Algebra
Boolean laws
46
Unit-I Number system and Boolean Algebra
Summary
• Computers are binary devices
– We’re forced to think in terms of base 2.
– We learned how to convert numbers between
binary, decimal, octal and hexadecimal
• We’ve already seen some of the recurring
themes of architecture:
– We use 0 and 1 as abstractions for analog voltages.
– We showed how to represent numbers using just
these two signals.