Sie sind auf Seite 1von 8

CS210 Computer Logic

Chapter 1: Digital computers and information


Information representation:
1. A bit (o or 1) is represented by a voltage value rage. For example,
from 4.0 to 5.0 volts for 1 and from 0.0 to 1.0 volts for 0.
2. The two voltage ranges must be non-overlapping ranges.
3. Combinations of 0s and 1s according to some alphanumeric code
are usually used to represent digits, characters, and other symbols.
4. The most important alphanumeric codes are ASCII and UNICODE.
5. ASCII uses 7 or 8 bits to represent 128 or 256 symbols See Table 1-3 in the
textbook.
6. UNICODE uses 16 bits to represent 256x256 symbols. It has been used to
represent the alphabets of many languages.
7. Parity bits: to detect errors in data communication and processing, one or
more bits are added to the combinations of alphanumeric codes to make the
number of 1s in each symbol either even or odd (all even or all odd). Such
bits are called parity bits. For example, an eight bit can be added to the
ASCII code.
8. A single parity bit can detects all single errors. Because a single error
changes the number of 1s from even to odd or from odd to even.
Number Systems
9. To perform the arithmetic and logical operations efficiently, numbers are
represented according to base representation. The most popular base is the
binary (base 2); and its digits are 0 and 1; and 10 represents the decimal 2.
10. The digits of the decimal system are 0,1,2,3,4,5,6,7,8, and 9.
11. The digits of octal system are 0,1,2,3,4,5,6, and 7; and 10 represents the
decimal 8.
12. The digits of hexadecimal system are 0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, and
F; 10 represents the decimal 16. The decimal values of A,B,C,D,E, and F
are 10,11,12,13,14,and 15, respectively.

13. If A =AnAn-1A1A0 . A-1A-2A-m is a number in base r, the decimal


value equivalent equals
An rn + An-1 rn-1+ +A1 r +A0 r0 + A-1 r -1+A-2 r 2 ++A-m r -m
An is referred to as the most significant digit (msd); and A-m is referred to as
the least significant digit(lsd).The number A is referred to as Ar .
14. The previous formula can be used to convert a number in base r to
decimal.
15. The following example illustrates a procedure for converting a decimal
integer to binary:
41/2 = 20 + 1/2
20/2 = 10 +0/2
10/2 = 5 + 0/2
5/2 = 2 + 1/2
2/2 = 1 + 0/2
1/2 = 0 + 1/2

Remainder = 1
=0
=0
=1
=0
=1

The least significant digit

The most significant digit

Left-to-right = Bottom-to-up
(41)10 = (101001)2
16. The following example illustrates a procedure for converting a decimal
fraction to binary:
0.6875 x 2 = 1.3750
0.3750 x 2 = 0.7500
0.7500 x 2 =1.5000
0.5000 x 2 =1.000

Integer = 1 The most significant digit


=0
=1
= 1 The least significant digit

Left-to-right = Top-to-down
(0.6875.10 = (0.1011)2
17. The preceding two procedures can be also used to convert a decimal number
to its representation in other bases.
18. To convert an octal number to binary, replace each octal number by
its 3-bit binary equivalent using the following table:

000
001
010
011
100
101
110
111

For

0
1
2
3
4
5
6
7

19. To convert a binary number to octal, start from the binary point from left to
right partition the binary number into 3-bit sequences( add 0's to the left if they
are needed) and then replace each 3-bit sequence by its octal equivalent. To
convert the fraction part, start from the binary point from right to left, partition
the fractional part into 3-bit sequences( add 0s to the right if they are needed) and
then replace each 3-bit sequence by its octal digit equivalent.
20. To convert a hexadecimal number to binary and visa versa, follow the
previous two procedures using 4-bit sequences and the following table:
Binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

Hexdigit
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

21.To convert a decimal number to octal, convert it to binary; and then convert

it to octal.
22. To convert a decimal number to hexadecimal, convert it to binary; and then
convert it to hexadecimal.
23.To convert an octal number to decimal, convert it to binary; and then convert
it to decimal.
24..To convert a hexadecimal number to decimal, convert it to binary; and then
to decimal.
Binary Arithmetic
25. The addition, subtraction, multiplication, and division procedures are very
similar to those used in decimal arithmetic and according to the following
rules:
0+0=0
0+1=1+0=1
1 + 1= 10 ( the sum = 0 and the carry = 1)
0-0=0
1-0=1
1- 1 = 0
0 - 1 = 1 and the borrow = 1

0 x 0 =0
0 x 1 = 1 x 0 =0
1x1=1
26. The following examples illustrate binary arithmetic:
Carries:

101100
10110
+ 10111
______________
101101

Borrows:

11
1011 0
_ 1001 1

____________
000 1 1
Borrows:

1111
10000
_
1111
____________
000 01

1011
X 101
____________
1011
0000
1011
_____________
110111
Representation of Negative Numbers
27. For negative integers, there are two representation methods:
Ones Complement: For positive numbers, unsigned representation is used. For a
given negative x, the Ones Complement representation of x is 2n x, where n is
the number of bits used to represent x. It is easy to show that the Ones
Complement of x can be obtained by complementing each bit of x. For example,
if x= 0011011 then x is represented by 1100100.
Twos Complement which is the most popular representation: For positive
numbers, unsigned representation is used. For a given negative x, the Twos
Complement representation of x is 2n x+1, where n is the number of bits used
to represent x. It is easy to show that the Twos Complement of x can be
obtained by complementing each bit of x and then adding 1. For example, if x=
0011011 then x is represented by 1100101.

Number Range

28. The following table shows all possible values represented using three bits in the
three systems

Binary
000
001
010
011
100
101
110
111

Unsigned
0
1
2
3
4
5
6
7

2sComplement
0
1
2
3
-4
-3
-2
-1

Sign-Magnitude
0
1
2
3
-0
-1
-2
-3

Unsigned range is 0<=X<=23-1


2sComplement range is -23-1 <=X <=23-1 -1
Sign-magnitude range is -(23-1 -1) <=X<=23-1 -1
28.If n bits are available to represent binary numbers, then the range of decimal
values are:
(a) Unsigned integers from 0 to 2n - 1
(b) Signed integers from - 2n-1 +1 to 2n-1 - 1 assuming the most significant
bit is used for representing the sign
(c ) 2s complement from -(2n-1 -1) to 2n-1 -1
(d) Unsigned fractions from 0 to (2n - 1)/ 2n.

Exercises
1. Proof the previous statement.
2. Find the rang of 2s complement fractions .

Binary addition and subtraction of signed integers


29.The advantage of Twos Complement is that we can convert the subtraction
into an addition and consequently only one circuit is used for both addition
and subtraction. To perform subtraction M-N using 2's complement, the
subtrahend N is represented by the 2's complement notation and then
addition is performed instead of subtraction.
For a given n bits, the range of positive and negative integers x represented by
n bits is - 2n -1 <=x<=2n -1-1, where the negative integers are represented by
2s complement notation. Note that the most significant bit serves as the sign
bit, 0 for positive and 1 for negative.
30.To determine the correct answer of adding two integers M and N
represented by n bits and only n bits are available for representing the
answer, the following rules are followed after discarding the overflow bit
from the sign bit:
If both M and N are positive and the most significance bit (sign bit)of the answer is
zero, then the answer is correct.
If both M and N are positive and the most significance bit is one, the answer is
wrong because its representation requires n+1 bits(overflow).
If M>=0 and N<=0 and Absolute(N) >M, then the answer is correct and negative in
Twos Complement notation. To obtain the ordinary notation, compute its Twos
Complement.
If M>=0 and N<=0 and Absolute(N) <M, then the answer is correct
In the previous two cases, the hardware does not have to check whether
Absolute(N) >M or not. . It is enough to check that the sign bits of M and N are
different, which can be implemented by hardware using a very simple circuit that will
be discussed in the next chapter. If the most significant bit is 1, then the answer is
negative and in the 2s complement notation.
If M<=0 and N<=0 and the most significance bit of the answer is zero, then answer
is wrong(overflow).
If M<=0 and N<=0 and the most significance bit of the answer is one, then the
answer is correct.

The above steps can be summarized by the following algorithm for representing
integers in 2s complement and their addition and subtraction.
Step-1 Represent each integer using the 2s complement representation and the given
number of bits. Check whether the given integers are within the range of the 2s
complement according to the formula - 2n -1 <=x<=2n -1-1, where n is the number of
available bits.
If any integer is not within the range, the representations and the operation results are
not correct.
Step-2 If the operation is subtraction, convert the subtrahend into its 2s complement
and change the operation to addition.
Step-3 Perform the addition operation. Always discard the overflow bit from the sign
bit( i.e. the bit to the left of the representation) and follow the following rules:
If the two integers have different sign bits, the answer is always correct, and the
answer is in the 2s complement representation.
If the two integers have the same sign bit and the sign bit is different from the
answers sign bit, then the answer is incorrect due to overflow (i.e. the result cannot be
represented in 2s complement using the given number of bits.)
If the sign bits of two integers and the answer have the same value, then the answer is
correct, and the answer is in the 2s complement representation.

HW#1
1.1,1.2,1.4(a,b,d),1.5,1.7( using 2s complement only), 1.10, 1.11

Das könnte Ihnen auch gefallen