COMP-200: Intro to Computer Systems
Assignment 2
mo khan - 3431709
Choose ONE exercise each from Chapters 4 and 5
Chapter 4:
| Base (N) | N^8 | N^7 | N^6 | N^5 | N^4 | N^3 | N^2 | N^1 |
| ---- | - | - | - | - | - | - | - | - |
| 2 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 4 | 16,384 | 4,096 | 1,024 | 256 | 64 | 16 | 4 | 1 |
| 8 | 2097152 | 262144 | 32768 | 4096 | 512 | 64 | 8 | 1 |
| 10 | 10,000,000 | 1,000,000 | 100,000 | 10,000 | 1,000 | 100 | 10 | 1 |
| 16 | 268,435,456 | 16,777,216 | 1,048,576 | 65,536 | 4,096 | 256 | 16 | 1 |
8.times.map { |x| 2**x }.reverse
=> [128, 64, 32, 16, 8, 4, 2, 1]
8.times.map { |x| 4**x }.reverse
=> [16384, 4096, 1024, 256, 64, 16, 4, 1]
8.times.map { |x| 8**x }.reverse
=> [2097152, 262144, 32768, 4096, 512, 64, 8, 1]
8.times.map { |x| 10**x }.reverse
=> [10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]
8.times.map { |x| 16**x }.reverse
=> [268435456, 16777216, 1048576, 65536, 4096, 256, 16, 1]
- Given our discussion of positional numbering systems in Section 4.2.1, see whether you can determine the decimal value of the following numbers:
a. 133 (base 4) = 31 (base 10)
```plaintext
| 64 | 16 | 4 | 1 |
| -- | -- | - | - |
| 0 | 1 | 3 | 3 |
```
```ruby
(1*16) + (3*4) + (3*1)
=> 31
31.to_s(4)
=> "133"
```
b. 367 (base 8, also called octal) = 247 (base 10)
```plaintext
| 512 | 64 | 8 | 1 |
| --- | -- | - | - |
| 0 | 3 | 6 | 7 |
```
```ruby
(3*64) + (6*8) + (7*1)
=> 247
247.to_s(8)
=> "367"
```
c. 1BA (base 16, also called hexadecimal. B is the digit that represents 11; A is the digit that represents 10.) = 442 (base 10)
```plaintext
| 4,096 | 256 | 16 | 1 |
| ----- | --- | -- | -- |
| 0 | 1 | B | A |
| 0 | 1 | 11 | 10 |
```
```ruby
(1*256) + (11*16) + (10*1)
=> 442
442.to_s(16)
=> "1ba"
```
Chapter 5:
-
A memory unit that is said to be 640 KB would actually contain how many memory cells? What about a memory of 512 MB? What about a memory of 2 GB?
The standard cell size of each member cell is 8 bits or 1 byte.
| Value | Bytes | | ----- | ----- | | 640 KB | 655,360 | | 512 MB | 536,870,912 | | 2 GB | 2,147,483,648 |