[Computer Composition Principles] 2. Binary and hexadecimal conversion, hexadecimal subtraction, memory address offset calculation and capacity calculation

1. Hexadecimal conversion

1.1 Binary to hexadecimal

Because 2 4 = 16 2^4=1624=16 , so every 4 binary bits can be expressed as 1 hexadecimal. For example as follows:

  • 00001111(B) = F(H)、0xF、0x0F
  • 11111111(B) = FF(H)、0xFF
  • 111100001111(B) = F0F(H)、0xF0F
  • 1111111100001111(B) = FF0F(H)、0xFF0F

1.2 Convert hexadecimal to binary

Every 1 hexadecimal can be converted to 4 binary digits. For example as follows:

  • 0xF0F = 111100001111(B) = 0000111100001111(B)
  • 0xFF0F = 1111111100001111(B)

Second, base subtraction

2.1 Hexadecimal

For example: 0xA000 - 0x0800

  • Subtract from the end first: 0x0000-0x0000 of the last two digits = 0x0000
  • Subtract the third last digit from 0x0000 - 0x0800, because it is not enough to subtract, so borrow to get 16 (because it is a hexadecimal subtraction), that is, 16 - 8 = 8
  • Subtract 0xA000 - 0x0000 in the penultimate digit, because one bit has been borrowed, it becomes 0x9000 - 0x0000 = 0x9000,
    so the final answer is 0x9800

PS: It is easy to understand by analogy to binary subtraction

3. Memory address offset calculation

insert image description here

For example: If a building has a total of 100 floors, the bottom is floor 0, and the top is floor 99. Because there are n numbers from 0 to (n-1), as shown in the figure below:

insert image description here

3.1 Calculate the storage capacity based on the first and last addresses

The topic is as follows:
insert image description here
As shown in the figure below, the first address is 30000H, and the last address is AFFFFH.

Because the title states that the memory is compiled in bytes, it means that each address is a byte (that is, 1 byte is placed on each floor of the building, that is, 8 bits).

The question means storage capacity, that is, how many bits can be stored.


The solution is as follows:

  • Find the number of floors first:

    • AFFFF(H) - 30000(H) + 1 = 7FFFF(H) + 1 = 80000(H)
    • And 80000(H) = 1000-0000-0000-0000-0000(B) = 2^19, that is 2^19 Bytes
      insert image description here
    • And 2 1 0 = 1K 2^10 = 1K210=1K 2 2 0 = 1 M 2 ^ 20 = 1M 220=1M 2 3 0 = 1 G 2 ^ 30 = 1G 230=1G
    • Hence 2 ^ 19 bytes = 2 9 2^929 * 2 10 2^{10} 210 = 2 9 K b y t e s 2^9 Kbytes 29Kbytes = 2 9 K B 2^9 KB 29KB = 512 KB
      insert image description here
  • Therefore, the final answer is that it can store a capacity of 512 KB (as shown below):

insert image description here

3.2 Find the first address according to the last address and storage capacity

The topics are as follows:

insert image description here


The solution is as follows:

If the title does not specify, each address is 1 byte by default.

Because a total of 2KB is 2K Bytes or 2048 Bytes, it is necessary to convert 2000 (decimal) to hexadecimal.

Because of common sense, 1024 = 2 10 2^{10}210 , so 2000 =2 11 2^{11}211 = 2 followed by 1 0(B) = 1000-0000-0000(B) = 800(H) which is 0x800. See the figure below for details:

insert image description here

And because the formula is storage space = last address - first address + 1 storage space = last address - first address + 1storage=last addressfirst address+1 , so firstfirst address=last addressstorage+1 = 9FFF(H) - 0800(H) + 1(B) = A000(H) - 0800(H) = 9800(H). See the figure below for details:

insert image description here

Guess you like

Origin blog.csdn.net/jiaoyangwm/article/details/131343279