Solutions to Practice Problems

advertisement
Solutions to Practice Problems
Practice Problem 1.1
Express the binary number 110110 as a decimal number.
Solution:
1101102
 1  25  1  24  0  23  1 22  1 21  0  20
 5410
Practice Problem 1.2
Convert the decimal number 148 to binary.
Solution: We determine the largest power of 2 that is less than or equal to 148. 27  128 is a power of 2
that is less than 148, but is it the largest? We try 28 and see 28  256 , so the largest power of 2 less than or
equal to 148 is indeed 27 . Thus the binary representation of 148 will have a one in the 27  128 position:
1
____________
2  128
7
___________
____________
___________
__________
_________
_________
__________
2  64
2  32
2  16
2 8
2 4
2 2
20  1
6
5
4
3
2
1
Subtracting 128 from our number 148 gives 148 128  20 , and 20 is now the number we are working
with. We ask: What is the largest power of 2 that is less than or equal to 20? The answer: 24  16 . So,
the binary representation of 148 will have a one in the 24  16 position:
1
____________
2  128
7
1
___________
____________
___________
__________
_________
_________
__________
2  64
2  32
2  16
2 8
2 4
2 2
20  1
6
5
4
3
2
1
Subtracting 16 from our number 20 gives 4. The largest power of 2 that is less than or equal to 4 is 22  4
and the binary representation of 148 will have a one in the 22  4 position:
1
____________
27  128
1
1
___________
____________
___________
__________
_________
_________
__________
26  64
25  32
24  16
23  8
22  4
21  2
20  1
Now, subtracting 4 from our number 4 gives 0, so we are done. Filling in zeros in all remaining position
(i.e., all positions that do not have a 1), we have our answer: The decimal number 148 in binary is
1
____________
27  128
0
1
1
0
0
___________
0
____________
___________
__________
0
_________
_________
__________
26  64
25  32
24  16
23  8
22  4
21  2
20  1
or, 14810  10010100 2
Practice Problem 1.3
Express the hexadecimal number 3CB as a decimal number.
Solution:
3CB = 3  162  12  161  11 160 = 971
2
Practice Problem 1.4
Convert the decimal number 2576 to hexadecimal.
Solution. 160  1 , 161  16 , 162  256 , 163  4096 ... , so the number will
hexadecimal digits. There are ten 256’s within 2576, so our number is (so far)
have three
A _ _
2576 – (10)(256) = 16. The largest power of 16 less than or equal to 16 is 161 . There is one 16 in 16:
A 1 _
Subtracting 16 from 16 leaves zero, so we’re done. The answer is:
A10
Practice Problem 1.5
Convert the number 0x13F to binary.
Solution:
1 = 0001
3 = 0011 F = 1111
Thus 0x13F = 1 0011 1111
Practice Problem 1.6
Convert the binary number 110101001 to hexadecimal.
Solution:
1
1
1010
A
1001
9
= 1A9
Do you see why when you pair bits into groups of 4 you need to start at the right?
Practice Problem 1.7
Suppose the first byte of a variable is stored at memory location numbered:
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0
We say that this memory location is the address of the variable. What is this variable’s address in hexadecimal
notation?
Solution:
0000
0000
0001
0010
1111
1111
0111
1100
0
0
1
2
F
F
7
C
=
0012FF7C
Practice Problem 1.8
Memory addresses are 32-bit values represented in hexadecimal.
(a)
(b)
(c)
How many bytes are in a memory address?
How many words are in a memory address?
How many hexadecimal digits are in a memory address?
Solution: (a) 4
(b) 1
(c) 8
3
Practice Problem 1.9
The picture below shows nine consecutive memory locations in RAM. The address of the first location shown
is 0x08048374 and locations are numbered sequentially. The values stored at each address are also shown in
hexadecimal. For example, memory address 0x08048374 holds the value 0x55.
(a) Fill in the memory addresses for the last four locations.
(b) How many bytes are stored at each individual memory address?
Solution:
(a) The next four addresses are 0x08048379 , 0x0804837a , 0x0804837b and 0x0804837c.
(b) 1 byte (since it holds two hexadecimal digits, and each hexadecimal digit is four bits).
Practice Problem 1.10
How is the letter t stored in memory?
Solution:
The letter t is stored as hexadecimal 74, which is 01110100
Practice Problem 1.11
Consider the picture shown on the top of the previous page. Suppose you know that a character is stored at
memory location 0x08048374. What is stored at this memory location?
Solution:
The letter U is stored.
4
Download