Beruflich Dokumente
Kultur Dokumente
Remainder = 1
=0
=0
=1
=0
=1
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
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
Exercises
1. Proof the previous statement.
2. Find the rang of 2s complement fractions .
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