Download Conversions Among Number Systems

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

History of mathematics wikipedia , lookup

Musical notation wikipedia , lookup

Foundations of mathematics wikipedia , lookup

Big O notation wikipedia , lookup

History of logarithms wikipedia , lookup

Abuse of notation wikipedia , lookup

Ethnomathematics wikipedia , lookup

Rounding wikipedia , lookup

Collatz conjecture wikipedia , lookup

History of mathematical notation wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Large numbers wikipedia , lookup

Approximations of π wikipedia , lookup

Location arithmetic wikipedia , lookup

Horner's method wikipedia , lookup

Addition wikipedia , lookup

Arithmetic wikipedia , lookup

Positional notation wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
CSE 1400 Applied Discrete Mathematics
Conversions Between Number Systems
Department of Computer Sciences
College of Engineering
Florida Tech
Fall 2011
Conversion Algorithms: Decimal to Another Base
Conversion of Natural Numbers
Conversion of Integers
1
1
3
Biased Notation for Integers
4
Conversion of Rational Numbers
5
Conversion of Floating Point Numbers
7
Problems on Converting Decimal to Another Base
7
Conversion Algorithms: Another Base to Decimal
8
Conversion of Natural Numbers
Conversion of Integers
9
10
Conversion of Rational Numbers
11
Conversion of Floating Point Numbers
Floating Point Arithmetic
Machine Epsilon
11
12
13
Problems on Converting Another Base to Decimal
14
Abstract
Decimal notation using Arabic numerals is the standard system for
writing numbers in everyday life. However, in many computing applications, other notations are used. Chiefly: binary and hexadecimal.
Learning algorithms to translate names between these numerical systems forms a foundation for developing translations between more
complex languages.
Conversion Algorithms: Decimal to Another Base
Conversion of Natural Numbers
The unsigned whole numbers, the natural numbers, written in decimal 0, 1, 2, 3, 4, 5, . . . can be converted to binary by repeated division
cse 1400 applied discrete mathematics
conversions between number systems 2
by 2. Dividing a number by 2 produces one of two remainders: r = 0
or r = 1. The natural numbers can be converted to hexadecimal by
repeated division by 16. Dividing a number by 16 produces one of 16
remainder: r = 0 through r = 15 = F.
• Convert q = 14 to binary.
Repeatedly divide 14 and following quotients by 2 pushing the
remainder bits onto a stack.
Repeated Remaindering Mod 2
Quotients
Remainders
14
0
7
1
3
1
1
1
∴ ( 14 ) 10 = ( 1110 ) 2
• Convert q = 14 to hexadecimal.
Repeatedly divide 14 and following quotients by 16 pushing the
remainder hex-digits onto a stack.
Repeated Remaindering Mod 16
Quotients
Remainders
14
E
∴ ( 14 ) 10 = ( E ) 16
• Convert q = 144 to binary.
Repeated Remaindering Mod 2
Quotients
Remainders
144
0
72
0
36
0
18
0
9
1
4
0
∴ ( 144 ) 10 = ( 1001 0000 ) 2
• Convert q = 144 to hexadecimal.
Repeated Remaindering Mod 16
Quotients
Remainders
∴ ( 144 ) 10 = ( 90 ) 16
144
0
9
9
2
0
1
1
cse 1400 applied discrete mathematics
conversions between number systems 3
• Convert q = 143 to binary.
Repeated Remaindering Mod 2
Quotients
Remainders
143
1
71
1
35
1
17
1
8
0
4
0
2
0
1
1
∴ ( 143 ) 10 = ( 1000 1111 ) 2
• Convert q = 143 to hexadecimal.
Repeated Remaindering Mod 16
Quotients
Remainders
143
F
8
8
∴ ( 143 ) 10 = ( 8F ) 16
• Convert q = 255 to binary.
Repeated Remaindering Mod 2
Quotients
Remainders
255
1
127
1
63
1
31
1
15
1
7
1
3
1
1
1
2
0
1
1
∴ ( 255 ) 10 = ( 1111 1111 ) 2
• Convert 161 to binary.
Repeated Remaindering Mod 2
Quotients
Remainders
161
1
80
0
40
0
20
0
10
0
5
1
∴ ( 161 ) 10 = ( 1010 0001 ) 2
• Convert 161 to ternary.
Repeated Remaindering Mod 3
Quotients
Remainders
161
2
53
2
17
2
5
2
1
1
∴ ( 161 ) 10 = ( 12222 ) 3 . Notice that
161 = 1 · 3 4 + 2 · 3 3 + 2 · 3 2 + 2 · 3 1 + 2 · 3 0
cse 1400 applied discrete mathematics
conversions between number systems 4
Conversion of Integers
The signed integers can be represented in two’s complement notation. To write a decimal integer m in two’s complement notation do
the following.
1. Convert the natural number |m| to binary using repeated remaindering as described in the previous section.
2. Append a leading sign bit 0.
1. 161 → 1010 0001
2. 1010 0001 → 0 1010 0001
3. If m = +161, return 0 1010 0001
else (if m = −161) return
1 0101 1111
3. If m ≥ 0, return the result of step 2. Otherwise, if m < 0, return
the two’s complement of the result of step 2.
The two’s complement operation is performed as follows.
1. From right-to-left, copy each bit up to and including the first 1.
The two’s complement of a positive
integer is a negative integer. The two’s
complement of a negative integer is a
positive integer.
2. Flip (one’s complement) the remaining bits to the left.
The idea is: A number m and its negative −m add to 0. Therefore,
if m = 0100 1100 is a signed integer written in two’s complement
notation, then m and m’s complement (its negative) m add to 0.
1. This integer m = 0100 1100 is positive: It’s leading, left-most, bit is
0.
2. The value of m is decimal 76.
3. The two’s complement of m is m = 1011 0100.
The sum of m and m is shown below with carry bits on the top
row.
c
1 1 1 1 1 1 0 0 0
m = 0 1 0 0 1 1 0 0
m = 1 0 1 1 0 1 0 0
0
0
0
0
0
0
0
0
By construction, the sum of m and it’s two’s complement m is 2s
where s is the word length, size, or number of bits in m.
s 0’s
m + m = 2s = 1 0000 · · · 0000
To write 2s in binary requires s + 1 bits. On an s bit computer the
overflow, last carry, bit is discarded. Therefore, on an s bit computer
s 0’s
m + m = 0 =0000 · · · 0000
Consider this example. Let m = 227 which when written as an
unsigned binary number, is 1100 0111. To write m as a signed binary
number, append a leading 0 so that
+227 = 0 1100 0111
To write 2 = (10)2 requires 2 bits. To
write 22 = (100)2 requires 3 bits. To
write 28 = (1000)2 requires 4 bits.
cse 1400 applied discrete mathematics
conversions between number systems 5
To write −227, perform the two’s complement operation on 0 1100 0111
to get
−227 = 1 0011 1001
Biased Notation for Integers
Biased notation is an alternative method used to represent signed
integers. Biased notation represents an integer n as
nb = n + b
where b ≥ 0 is called the bias or excess. Adding a bias b to an
integer n translates it to the right giving it a a new name. To
compute the value n of a biased integer nb , solve the equation nb =
n + b for n = nb − b, that is, subtract b from nb .
For illustration, we’ll use 8 bit strings .
(b7 b6 b5 b4 b3 b2 b1 b0 )b=127
Each bi is either a 0 or a 1 for each i = 0, . . . , 7. Using a bias of
b = 127 the 256 integers from −127 to 128 are named 0 to 255.
For instance, consider the biased number
(1111 1100)b=127 = nb = n + b = (1111 1100)2 + 127
Horner’s rule converts the binary number (1111 1100)2 to 252.
Horner’s Rule
1
1 1
2 6
1
14
1
30
1
62
0
126
1
3
15
31
63
126
7
For instance, pick a bias b = 32, and
notice the integers from n = −32 to
n = 31 map to biased integers from
n32 = 0 to n32 = 63.
Let n = −37 and let the bias be b = 127.
Then the biased number (−37)127 =
(n)b = n + b = −37 + 127 = 90 is the
biased name for the value −37.
The subscript b = 127 is a hint to interpret the bit string as biased number
with bias b = 127. Drop it when this is
clear from context.
The diagram show the integers from
−127 to 128 along the top line. The bottom line shows the biased numbers 0
to 255 which are used to name integers
from −127 to 128.
−127
128
0
0
252
252
Subtract the bias b = 127 from n + b = 252 to get n = 125 as the value
of the biased number
(1111 1100)b=127 = 125
Biased notation is used to encode positive and negative exponents
in floating point notation. That is, let
t = ±1. f × 2eb
be a normalized floating point number. The exponent eb is a biased
integer. As a small example, the bias could be b = 4 and exponents
from e4 = 0 to e4 = 7 represent values −4 to 3.
255
cse 1400 applied discrete mathematics
conversions between number systems 6
Conversion of Rational Numbers
To convert a positive rational number a/b, written in decimal notation, to another base do the following.
1. Write the number in fixed point notation: w. f
2. Convert the whole number part w as described in Conversion of
Natural Numbers.
3. Convert the fractional number part f by repeated multiplication
by 2 (or the appropriate base) inserting the overflow bit into a
queue.
Often the fractional part will not
terminate as a finite string.
• Convert q = 39/4 to binary
1. Write 39/4 as 9.75
2. Convert 9 to binary 1001.
3. Convert 0.75 to binary.
Repeatedly multiply 0.75 and following products by 2 inserting
the overflow bits into a queue.
Repeated Multiplying Mod 2
Fraction
Overflow
0.75
1.5
1
1.0
1
0.0
0
∴ ( 39/4 ) 10 = ( 1001.11 ) 2
Note that the binary fraction 0.11 represents the value 0.75 =
0.50 + 0.25
3
0.11 = 1 · 2 − 1 + 1 · 2 − 2 =
4
• Convert q = 14/3 to binary
1. Write 14/3 as 4.333 · · ·
2. Convert 4 to binary 100.
3. Convert 0.333 · · · to binary.
Repeatedly multiply 0.333 · · · and following products by 2
inserting the overflow bits into a queue.
Repeated Multiplying Mod 2
Fraction
Overflow
0.333 · · ·
0.666 · · ·
0
∴ ( 14/3 ) 10 = ( 100.0101 · · ·) 2
1.333 · · ·
1
0.666 · · ·
0
1.333 · · ·
1
Note the identity
1
1
1
1
1
= +
+
+··· =
3
4
16
64
4
1
1−
!
1
4
cse 1400 applied discrete mathematics
conversions between number systems 7
• Convert q = 1/7 to binary
1. Write 1/7 as 0.142857 · · ·
2. Convert 0 to binary 0.
3. Convert 0.142857 · · · to binary.
Repeatedly multiply 0.142857 · · · and following products by 2
inserting the overflow bits into a queue.
Repeated Multiplying Mod 2
Fraction
Overflow
0.142857 · · ·
0.285714 · · ·
0
0.571428 · · ·
0
0.142857 · · ·
1
∴ ( 1/7 ) 10 = ( 0.001001 · · ·) 2
0.285714 · · ·
0
0
1
Note the identity
• Convert q = 57/5 to hexadecimal
1
1
1
1
1
= + 2 + 3 +··· =
7
8
8
8
8
1. Write 57/5 as 11.4 · · ·
1
1−
!
1
8
2. Convert 11 to hexadecimal B.
3. Convert 0.4 · · · to hexadecimal.
Repeatedly multiply 0.4 · · · and following products by 16 inserting the overflow hex-digits into a queue.
Repeated Multiplying Mod 16
Fraction
Overflow
0.4 · · ·
6.4
0
6.4
6
6.4
6
6.4
6
∴ ( 57/5 ) 10 = ( B.666 · · ·) 2
Note the identity
6
6
2
6
6
+
+··· =
=
+
5
16 162 163
16
Conversion of Floating Point Numbers
A floating point number written in decimal can be converted to another base by writing the number in fixed point notation and using
the methods of the previous section.
• Convert 3.75 × 10−1 to octal.
1. Write 3.75 × 10−1 as 0.375.
2. Repeatedly multiply 0.375 · · · and following products by 8
inserting the overflow octal-digits into a queue.
Repeated Multiplying Mod 8
Fraction
Overflow
0.375 · · ·
∴ 3.75 × 10 − 1 = ( 0.3 ) 8
3.0
3
0.0
0
0
0
1
1
1 − 16
!
cse 1400 applied discrete mathematics
conversions between number systems 8
• Convert 2.997 × 10 2 to hexadecimal.
1. Write 2.997 × 10 2 as 299.7.
2. Convert 299 to hexadecimal
Repeated Remaindering Mod 16
Quotients
Remainders
299
B
18
2
1
1
∴ 299 = ( 12B ) 16
3. Repeatedly multiply 0.7 · · · and following products by 16
inserting the overflow hex-digits into a queue.
Repeated Multiplying Mod 16
Fraction
Overflow
0.7
0.2
B
0.2
3
0.2
3
3
∴ 2.997 × 10 2 = ( 12B.B333 · · ·) 16
Problems on Converting Decimal to Another Base
1. Convert the following natural numbers (all named q) from decimal to binary.
(a) q = 13.
(c) q = 145.
(b) q = 134.
(d) q = 257.
2. Convert the following natural numbers from decimal to hexadecimal.
(a) q = 13.
(c) q = 145.
(b) q = 134.
(d) q = 257.
3. Convert the following signed integers from decimal to two’s complement binary.
(a) q = −13.
(c) q = −145.
(b) q = +134.
(d) q = −257.
4. Convert the following signed integers from decimal to biased
decimal notation.
Repeatedly divide q and following
quotients by 2 pushing the remainder
bits onto a stack.
Instead of dividing by 16 and stacking
remainders, it may be easier to convert
to binary and group bits by fours.
cse 1400 applied discrete mathematics
conversions between number systems 9
(a) q = −13 with bias b = 32.
(c) q = −145 with bias b = 256.
(b) q = +134 with bias b = 256.
(d) q = −257 with bias b = 512.
5. Convert the following rational numbers, written in decimal, to
binary.
(a) q = 27/8.
(c) q = 0.3125.
(b) q = 5.1.
(d) q = 0.3333 · · · .
Conversion Algorithms: Another Base to Decimal
Horner’s rule is a key algorithm for converting a number, written in base b, to decimal.
A number m written in base b can be expressed in polynomial
form.
m = a n −1 b n −1 + a n −2 b n −2 + · · · + a 1 b 1 + a 0 b 0
where the coefficients an−1 , an−2 , . . . , a1 , a0 are numbers in the set Zb
of integers mod b
Zb = {0, 1, 2, . . . , (b − 1)}
Horner’s rule can be comprehended by parenthesizing the operations
required to evaluate the value of m.
m = (· · · (( an−1 b + an−2 )b + an−3 )b + · · · + a1 )b + a0
There are at least two choices for storing the coefficients: Littleendian
$[a_{0},\,a_{1},\,a_{2},\ldots,\,a_{n-2},\,a_{n-1}]$
and big-endian
$[a_{n-1},\,a_{n-2},\,a_{n-3},\ldots,\,a_{1},\,a_{0}]$
If the coefficients are stored in little-endian, then
horner
horner
horner
horner
:: Float -> [Float] -> Float
c [] = 0
c [x] = x
c (x:xs) = x + c * (horner c xs)
horner
horner
horner
horner
:: Float -> [Float] -> Float
c [] = 0
c [x] = x
c (x:xs) = horner c ([c * last xs]++tail xs)
or
cse 1400 applied discrete mathematics
conversions between number systems 10
horner
horner
horner
horner
:: Float -> [Float] -> Float
c [] = 0
c [x] = x
c (x:xs) = horner c ([c * x + head xs]++tail xs)
Conversion of Natural Numbers
Consider the natural number forty-one. Written in binary, forty-one
is (0010 1001)2 . Horner’s rule will convert this string into its decimal
form: (41)10 .
Table 1: Converting (0011 0101)2 to
(41)10 .
Horner’s Rule
0
0 1 0 1
0 0 2 4
0
10
0
20
0
0
10
20
1
2
5
1
40
41
In a like manner 123 written in binary is (0111 1011)2 . This can be
checked by Horner’s rule.
Horner’s Rule
0
1 1 1
0 2 6
1
14
0
30
1
60
0
1
15
30
61
3
7
1
122
123
Horner’s rule can convert octal (737)8 to decimal using 8 as the multiplier. The computation is summarized in the table below.
Horner’s Rule
7
3
56
7
59
7
472
479
Notice that
(737)8 = 7 · 82 + 3 · 8 + 7 = 479
Choose a base 2 ≤ b < 10 and a string over that base. Convert the
string to decimal using Horner’s rule. Show that you understand
how the string you wrote represents the decimal value computed by
Horner’s rule.
cse 1400 applied discrete mathematics
conversions between number systems 11
Conversion of Integers
Signed integers can be written in two’s complement notation. By
construction, an integer m and it’s two’s complement m sum to 2s
where s is the word size of m.
To convert the two’s complement binary number m = 0 1100 1000
to decimal do the following.
1. Recognize that m is positive: It’s leading, left-most, bit is 0.
2. Use Horner’s rule to convert 0 1100 1000 to decimal.
Horner’s Rule
0
1 1 0
0 2 6
0
12
1
24
0
50
0
100
0
200
0
1
12
25
50
100
200
3
6
∴ 0 1100 1000 = +200.
To convert the two’s complement binary number m = 1 1100 1000 to
decimal do the following.
1. Recognize that m is negative: It’s leading, left-most, bit is 1.
2. Method 1: Use Horner’s rule to convert 1 1100 1000 to decimal.
Horner’s Rule
1
1 1
2 6
0
14
0
28
1
56
0
114
0
228
0
456
1
3
14
28
57
114
228
456
7
Subtract 29 = 512 to get 456 − 512 = −56 ∴ 1 1100 1000 = −56.
3. Method 2: Compute the two’s complement of 1 1100 1000 to get
0 0011 1000. Convert to decimal (in your head or by Horner’s rule)
to get 56. Negate the result. ∴ 1 1100 1000 = −56.
Conversion of Rational Numbers
The rational number two and nine-sixteenth when written in binary
is (0010.1001)2 . Horner’s rule followed by division by 24 will convert
this string into its decimal fraction form: 41/16. Notices the similarity of division by 2 to the fourth and writing 3.1415 as 31415/104 .
Horner’s Rule
0
0
0
1
0
0
2
1
4
0
10
0
20
0
0
1
2
5
10
20
1
40
41
Figure 1: Converting (0011.0101)2 to
41/16.
cse 1400 applied discrete mathematics
conversions between number systems 12
Conversion of Floating Point Numbers
Floating point numbers are commonly used to approximate the real numbers. It is beyond the scope of this course to
provide a complete description of floating point numbers, but some
essential ideas should be known before writing solutions to problems
that involve real numbers.
Floating point notation is built upon scientific notation. In general, rational numbers written in scientific notation have the form
t = ±d. f × 10
e
where d is a non-zero digit, f is a decimal string, and e is a base 10
exponent.
To gain understanding of floating point numbers let’s consider
how to write rational numbers in the form
For instance, the scientific notation for
0.577215 is 5.77215 × 10−1 .
Restricting the leading digit to be nonzero is called This avoids multiple
representations for identical values.
For instance, −0.0060221415 × 1026 is
normalized as −6.0221415 × 1023 .
In computing practice, t could be stored
as a concatenated string t = s e d f ,
where s is a sign bit.
t = ±1. f × 2e
where 8 bits are used to encode the sign, the fraction f , and the exponent e. Denote this set of floating pointing numbers F.
A binary floating point number t ∈ F is an 8-bit string that is
parsed into three parts as shown below.
Sign Bit
Exponent (bias=3)
Fraction
s
e2 e1 e0
f −1 f −2 f −3 f −4
The sign bit s controls the whether the floating point number is positive or negative.
The next three bits e = e2 e1 e0 encode a base 2 exponent written in
biased notation, with bias b = 3. That means the biased exponents in
the range h000, . . . , 111i represent the natural numbers in the range
h−3, . . . , 4i.
The four fraction bits f = f −1 f −2 f −3 f −4 encode the natural numbers from 0 to 15, but their value is interpreted as
The sign bit s conveniently encodes the
sign of t by the function (−1)s . When
s = 0 the floating point number is
positive. When s = 1 the floating point
number is negative.
( f −1 f −2 f −3 f −4 )2
f
=
16
24
Finally, except for 0, which is the all zero string 0 000 0000, we assume that all floating point numbers are normalized.
Therefore, if
t = s e2 e1 e0 f −1 f −2 f −3 f −4 = s e f
is a floating point number, it represents the rational number
f
s
× 2e
t = (−1) 1 +
16
This is similar to writing the decimal
number 0.3141 as 3141/104 .
cse 1400 applied discrete mathematics
conversions between number systems 13
where s ∈ B, 0 ≤ f ≤ 15, and −3 ≤ e ≤ 4. The eight line graphs that
follow show the distribution of these floating point numbers at each
exponential scale.
0
17
128
24
128
31
128
x
0
16
64
24
64
31
64
x
0
16
32
24
32
31
32
x
0
1
24
16
31
16
x
0
2
3
31
8
x
0
4
6
31
4
x
0
8
12
31
2
x
0
16
24
31 x
Floating Point Arithmetic
Floating point number systems are rife with arithmetic errors. Even
the most basic rules do not apply.
• Floating point arithmetic is not closed under addition. For
instance
t = 16 = 1.0 × 24 = (0 111 0000) f p
and
s = 1.0 × 2−1 = 0.5 = (0 010 0000) f p
are floating point number, but their t + s = 16.5 sum is not a
number in this system.
• Floating point arithmetic is not associative. For instance
(16 + 0.5) + 0.5 = 16 but 16 + (0.5 + 0.5) = 17
There are several measures of floating point errors that occur when
approximating arithmetic over the real numbers.
Let t( x ) be the floating point number closest to real number x.
Then e( x ) = | x − t( x )| is the rounding error in approximating x
by floating point number t( x ). As the graphs above show, the rounding error increases as the magnitude of x increases. The relative
error in approximating x 6= 0 by t( x ) is defined to be
E( x ) =
| x − t( x )|
e( x )
=
|x|
|x|
Look at the first line graph above, where the magnitude of scale is
the smallest.
Addition is computed by (a) aligning exponents to the higher power:
1.0 × 24 + 0.00001 × 24 ; (b) and
adding fractional parts 1.00001 × 24 ,
and truncating to the accuracy of
the system, in our system, 4 places
to the right of the binary point:
16 + 0.5 = 1.0000 × 24 = 16.
cse 1400 applied discrete mathematics
conversions between number systems 14
0
8
128
16 17
128 128
24
128
31
128
The floating point number closest to x = 8/128 = 1/16 is t = 0.
Therefore 1/16 rounds to 0. The rounding error is e(1/16) = 1/16
and the relative error is E(1/16) = 1.
The floating point number closest to x = 16/128 = 1/8 is
t = 17/128. Therefore 1/8 rounds to 17/128. The rounding error
is e(1/8) = 1/128 and the relative error is E(1/8) = 1/16.
The floating point number closest to x = 33/256 is t = 17/128.
Therefore 33/256 rounds to 17/128. The rounding error is e(33/256) =
1/256 and the relative error is E(33/256) = 1/33.
Real
x
FloatingPoint
t( x )
RoundingError
e( x )
RelativeError
E( x )
8
128
16
128
33
256
33
128
33
64
33
32
33
16
33
8
33
4
33
2
0
1
16
1
128
1
256
1
128
1
64
1
32
1
16
1
8
1
4
1
2
1
17
128
17
128
16
64
16
32
16
16
16
8
16
4
16
2
16
1
1
16
1
33
1
33
1
33
1
33
1
33
1
33
1
33
1
33
Machine Epsilon
In floating point arithmetic, n = 5 is the power of 2 such that
1 + 2−n = 1. The value e = 2−5 = 1/32 is called the machine’s
epsilon and measures accuracy or inaccuracy to floating point arithmetic.
1 = 1 + 2−6 = 65/64 6∈ F
1 = 1 + 2−5 = 33/32 6∈ F
1 < 1 + 2−4 = 17/16 ∈ F
Problems on Converting Another Base to Decimal
1. Use Horner’s rule to convert the following unsigned numbers into decimal notation.
(a) (0000 1001)2
(b) (1111 1111)2
(c) (1100 1100)2
(d) (1010 1010)2
(e) (747)8
(f) (123)4
(g) ( A47)16
2. Convert the signed decimal integers below into two’s complement notation.
x
cse 1400 applied discrete mathematics
conversions between number systems 15
(a) +76.
(c) −137.
(b) −76.
(d) +177.
3. Negate the two’s complement integers below.
(a) 0100 1100.
(c) 1010 0100.
(b) 1100 0000.
(d) 1000 0000.
4. Convert the following two’s complement integers into decimal notation.
(a) 0100 1100.
(d) 0010 1000.
(b) 1100 0000.
(e) 62A3.
(c) 1010 0100.
(f) C01B.
5. Using two’s complement notation what range of integers from most negative to most positive can be
represented using
(a) 2 bits?
(c) 32 bits?
(b) 8 bits?
(d) 64 bits?
6. Consider ten’s complement notation. An integer and its complement should sum to zero. Writing in 4
digits the integer 1234 has complement 8766 since 1234 + 8766 = 1 0000. The smaller numbers from
0000 to 4999 are positive and have their “normal” value. The larger values 5000 to 9999 are negative and
defined by the complement rule illustrated in the example.
(a) What are the complements of (a) 3141? (b) 7316? (c) 9999? (d) 5000?
(b) What are the decimal numbers for the ten’s complements numbers (a) 3141? (b) 7316? (c) 9999? (d)
5000?
7. The following binary strings are floating point numbers where the first (leftmost) bit is a sign bit, the
next three bits are exponent bits written in biased notation with bias b = 3, and the last four bits are
fraction bits. These floating point are normalized. What are decimal names for these floating point numbers?
(a) 1001 1000
(c) 1111 1111
(b) 0101 1011
(d) 0000 0001
8. Using the 8 bit floating point numbers from the course, explain why 17/128 is the smallest positive
floating point number and why 1/8 is not.