DLD CH#1B

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Common Powers (1 of 2)

• Base 10 Power Preface Symbol Value


10-12 pico p .000000000001

10-9 nano n .000000001

10-6 micro  .000001

10-3 milli m .001

103 kilo k 1000

106 mega M 1000000

109 giga G 1000000000


1012 tera T 1000000000000
Common Powers (2 of 2)
• Base 2
Power Preface Symbol Value
210 kilo k 1024

220 mega M 1048576

230 Giga G 1073741824

• What is the value of “k”, “M”, and “G”?


• In computing, particularly w.r.t. memory, the base-2
interpretation generally applies
Review – multiplying powers
• For common bases, add powers
ab  ac = ab+c

26  210 = 216 = 65,536


or…
26  210 = 64  210 = 64k
Binary Addition (1 of 2)
• Two 1-bit values

A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition (2 of 2)
• Two n-bit values
• Add individual bits
• Propagate carries
• E.g.,
1 1
10101 21
+ 11001 + 25
101110 46
Binary Subtraction
• Two 1-bit values
A B A-B
0 0 0
1 0 1
0 1 1 with a borrow
1 1 0 of 1 is equivalent
to 10 – 1 = 1
Ex. Binary Subtraction
Ex. 111 110.01
010 100.10
101 001.11

1’s complement: To obtain 1’s complement of a binary


number change each 0 to a 1 and each 1 to a 0.
Binary number 1’s Complement
0101 1010
1001 0110
1101 0010
0001 1110
Step of 1’s Complement Subtraction
The following points should be noted down when we do 1’s
complement subtraction.
1. Write the first number (minuend) as such.
2. Write the 1’s complement of second number(subtrahend)
3. Add the two numbers.
4. The carry that arises from the addition is said to be “end around carry”.
5. End-around carry should be added with the sum to get the result.
6. If there is no end around carry find out the 1’s complement of
the sum and put a negative sign before the result as the result
is negative.
1’s Complement Subtraction
Instead of subtracting the second number from the first, the 1’s
complement of the second number is added to the first number. The last
carry which is said to be a END AROUND CARRY, is added to get the
final result.
E.g.:
7 111 -----------------> 111 +
3 011 1’s complement 100
4 1011 +
└→1
100 result
Cont’d
 If there is no carry in the 1’s complement subtraction, it
indicates that the result is a negative and number will be in its
1’s complement form. So complement it to get the final result.

Eg.
8 - 1000 -----------------> 1000 +
10 1010 1’s complement 0101
2 1101 1’s complement -0010 result
2’s Complement
➔ 2’s complement results when we add ‘1’ to 1’s complement of the given
number i.e. 2’s complement =1’s complement + 1

Binary Number 1’s complement 2’s complement


1010 0101 0110
0101 1010 1011

Steps of 2’s Complement Subtraction


1. Write the first number as such
2. Write down the 2’s complement of the second number.
3. Add the two numbers.
4. If there is a carry, discard it and the remaining part (sum) will be the
result (positive).
5. If there is no carry, find out the 2’s complement of the sum and put
negative sign before the result as the result is -ve.
Cont’d
E.g.:
1) 10 - 1010 -----------------> 1010 +
8 1000 2’s complement 1000
2 1 0010
0010 result

2) 5 - 0101 -----------------> 0101 +


12 1100 2’s complement 0100
4 1001 2’s complement – 0111 result
Multiplication
• Decimal (just for fun)
35
x 105
175
000
35
3675
Multiplication
• Binary, two 1-bit values

A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication
• Binary, two n-bit values
• As with decimal values
• E.g.,
1110
x 1011
1110
1110
0000
1110
10011010
Binary Division

The table for binary division is as follows.


0÷1=0
1÷1=1
As in the decimal system division by zero is meaning less
Fractions
• Decimal to decimal (just for fun)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14
Fractions
• Binary to decimal
10.1011 => 1 x 2-4 = 0.0625
1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions
• Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001...
etc.
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Don’t use a calculator!
Skip answer Answer

Skip answer Answer


Exercise – Convert …
Answer

Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
1.3 Binary Codes
Binary Coded Decimal(BCD)
 Binary Coded Decimal(BCD) is a way to express each of the decimal
digits with a binary code.
 In BCD each decimal digit , 0 through 9 is represented by a binary code
of four bits.
The designation of 8421 indicates the binary weights of the four bits
(23,22,21,20). The largest 4-bit code is 1001.
 The numbers 1010, 1011, 1100, 1101,1110, and 1111 are called
forbidden(Invalid) numbers. The following table represents the
decimal and 8421 equivalent numbers.
Invalid Codes of BCD

In 8421(BCD) code only six code combinations that are not
used (Invalid codes) which are
1010,1011,1100,1101,1110,1111
But we can use the rest ten combinations.

To express any decimal number in BCD, simply replace each


decimal digit with the appropriate 4- bit code .
Convert From Decimal Number to BCD
To express any decimal number in BCD, simply replace
each decimal digit with the appropriate 4-bit code.

Ex. Convert the following Decimal number to BCD


Convert From BCD to Decimal Number

 Easy to determine a decimal number from a BCD number.


Start at the right most bit (LSB) and break the code into
groups of four bits. Then write the decimal digit represented
by each 4-bit group.
 Convert each of the following BCD code to Decimal
BCD Addition
BCD is a numerical code and can be used in arithmetic operations.
How to Add two BCD numbers:-
Step 1)- Add the two BCD numbers, using the rules or binary addition .
Step 2)- If a 4-bit sum is equal to or less than 9, it is a valid BCD numbers.
The Bit greater than 9
 Step3)- If a 4-bit sum is greater than 9, it is an invalid result. To
make it a valid result Add 6 (0110) to the 4 bit sum and return the valid
code of 8421.If it is a carry simply add the carry to the next 4-bit group.

 Add the following BCD numbers:


Cont’d
Digital Code
➢ Digital codes are an alphanumeric code used to represent
numbers, letters, symbols and instructions.
➢ A minimum alphanumeric code must represent 10 decimal
digits and 26 letters of alphabet, total of 36 items.

➢ Type of digital codes


Gray Code, and ASCII code
➢ Gray Code
The Gray code is unweighted and is not an arithmetic
code; that is, there are no specific weights assigned to the
bit positions.
➢ Gray code :- a code only a single bit change from one code
word to the next in sequence.
Cont’d
➢ 4-bit Gray code for decimal numbers 0 through 15. Binary
numbers are shown in the table.
➢The single bit change between successive Gray code words.
Binary-to-Gray code Conversion
Step 1)- The most significant bit(MSB) in the Binary number is the same as the
corresponding MSB in the Gray code.
Step 2)- Going from left to right, add each adjacent pair of binary code bits to get
the next Gray code bit.
Gray-to-Binary code Conversion
Step 1)- The most significant bit (left-most) in the Gray code is the same
as the corresponding bit in the Binary number.
Step 2)- Add each binary code bit generated to the Gray Code bit in the
next adjacent position GC. Discard carries.
ASCII Code
ASCII is the abbreviation for American Standard Code for Information
Interchange.
ASCII is a universal accepted alphanumeric code used in most computer and
other electronic equipment. Eg Computer Keyboards.
ASCII has 128 characters and symbols represented by a 7-bit binary code.
ASCII is 7-bit code of the form X6, X5, X4, X3, X2, X1, X0 .

ASCII used to code two types of information.


1) Printable character such as alphabets, digits and special characters.
2) Not printable |Controllable characters| used to control the operation of
the digital computer .
Cont’d
ASCII symbols which are letter of alphabet(lowercase and upper case), ten decimal digits,
punctuation signs and other commonly used symbols.
Cont’d
Error Detection and Correction Codes
➢ There are different method of Error detection and Correction methods
 Partial Method for Error Detection,
 Hamming Error Correction code(Reading Assignment)
 Many systems use a partial bit as a means for bit error detection.
 Any group of bits contain either an even or an odd number of 1s.
The table show an Even and Odd parity
Parity
➢ The parity bit can be attached to the code at ether the beginning or the
end, depending on the system design.
➢Notice that the total number of 1s, including the parity bit, is always
even for even parity and always odd for odd parity.
End of Chapter One

You might also like