注册 登录
编程论坛 C语言论坛

关于16进制与内存地址的几个疑惑

wufaxian 发布于 2021-09-19 21:01, 2308 次点击
今天看b站的《深入理解计算机系统》-------“信息的存储”部分,讲述了16进制以及内存地址相关内容。我看后有两个疑惑。
1、之所以引入16进制,视频中给出了原因“二进制表示法比较冗长,而十进制表示法与位模式表示法之间的转换又比较麻烦”-------------关于这一点我的疑惑是,所谓的位模式表示法。就是二进制表示法吧?如果是,我发现二进制和十六进制之间的转换也不简单。而且无论是二进制转十六进制,还是二进制转10进制。目前随便找个互联网网站都可以给你转换。因此所谓“转换又比较麻烦”看起来像个伪命题。因为二进制和十进制之间转换比较麻烦而引入十六进制似乎是为了解决一个问题而制造了新问题。
    如果我理解的不对,是否可以举个例子,可以体现引入十六进制带来的便捷?视频中还介绍了c语言中的十六进制编码。可是我过去简单学过c语言。似乎系代码的时候也用不上十六进制。大佬们可否给个例子

2、视频介绍内存中每个自己都有一个十六进制的地址。还讲了32位操作系统与64位操作系统 管理内存大小的差别。--------------我的问题是内存地址像是门牌号。但是这个门牌号是存放在哪里呢?这个门牌号本身是否占用内存空间呢?一个字节是32比特,那么这个字节对应的地址占用多少存储空间? 操作系统如何进行内存地址(16进制编码)和内存半导体硬件存储空间(内存物理地址)的一一对应呢?只有建立了这种对应关系,才能在需要的时候根据“内存地址(16进制编码)”找到对应的物理地址存放或读取数据吧。
  
3 回复
#2
自由而无用2021-09-19 21:14
https://www.
#3
自由而无用2021-09-19 21:26
Q1:
hex is much more convenient than binary, for example one cpu instruction:
"push ebp" correspond to machine code(intel) 0x55
0x55 is a form of hex opcode,and its binary form looks like this 0b01010101
which one do you think is much easier to remember?
Q2:
yes, address occupy a machine size, x86=32bit, x64=64bit, point to the 1st address of a block memory
Q3:
memory mapping or io mapping, using virtual address called mmu

maybe this isnot a very exactly reply, if you could get a little help, I'll be very happy
good luck!
#4
wufaxian2021-09-19 21:29
回复 2楼 自由而无用
谢谢回复,我看了一下机翻的网页。看后还不是很懂
#5
wufaxian2021-09-19 21:39
回复 3楼 自由而无用
谢谢你的回复。如你所说内存地址本身也占用内存空间。那就引出一个新问题。就是32位系统可以管理的内存空间是2^32=4,294,967,296字节。因为地址编码就是32位么。32位全用完了。理论上就没法管理更多的地址了。但是每个地址还要用32bit(4字节)空间。那这部分存放地址的内存空间也需要用地址吧?那这样不就变成循环占用了。最后内存里什么都没存。光存了一些地址。

即便没用循环占用。就是4,294,967,296字节,每个字节需要一个32bit(4字节)的空间存放地址。那“地址”占用的空间比其对应的那一字节空间还要大。感觉也行不通。最后内存里还是全都存放地址了,存不了其他数据了。

所以,是不是我哪里理解错了?
#6
自由而无用2021-09-19 21:54
address is a human-made conception, if you consider it as address,its just address, otherwise, its just a data
this is a very important thing, pointer is a dizzy conception, slowly slowly slowly to master it
#7
自由而无用2021-09-19 22:02
look at these 2 declarations:
int *p[1024];
int a[1024];

p = pointer(logical)
a = data(logical)
p = data(physical) dont think it as address
a = data(physical)
#8
自由而无用2021-09-19 22:13
and you referred to memory exhausted, thats the task managment of operation system, on x86 system windows 2(core)/2(usr), linux 1/3
#9
自由而无用2021-09-19 22:19
os is a smart guy, he knows how to manage the memory pool, include using swap page to take advantage of hard-disk resources

[此贴子已经被作者于2021-9-19 22:23编辑过]

#10
自由而无用2021-09-19 22:24
find a book of operating system to read

good luck!
#11
自由而无用2021-09-19 23:05
回复 5楼 wufaxian
there is a classic saying: procedure = data + algorithm
so, next time while you have been starting the lesson "data structure", put out your confusion to ask your mentor:
"why not include pointers"(procedure = data + algorithm + pointers)

[此贴子已经被作者于2021-9-19 23:06编辑过]

#12
自由而无用2021-09-20 09:47
About how to make a friend with pointer
just a data dat da d... important things speak 3 times!

int a; integer? yes
(int *)a pointer? yes
typedef int* pint;
(pint*)a pointerer? yes
typedef int(*func)(int, char **)
(func)a  function? yes

though they have different forms, they are all data
its all up to you whether the variable is a data or a pointer or sth else unless you want it to be a cat, thats impossible


#13
自由而无用2021-09-20 09:57
one more thing, when you start to learn assembly language, pay attention to the these 2 instructions:
x86[intel]
mov eax, dword ptr[esi]
lea ebx, dword ptr[edi]

its the principle of how a pointer works, indirect addressing
#14
laigaoat20052021-09-21 00:19
好多年没来过了,偶然想起,过来看看。

第一个疑惑:16进制的确比10进制更容易通过大脑转换,不需要计算器,当你熟悉后,可以很快想出来,甚至不用想都能写出任意大小的十六进制数据的二进制数据。比如0x1的二进制就是1,0x2就是10,0x4就是100,0x8就是1000。想明白了这四个特殊的数,其他数据就可以根据他们加出来:比如0x9就是1001。说到这,您应该理解了吧?这都不用想就能口算出来的,而十进制就没这么方便了。

第二个疑惑:门牌号不占用空间的。你的说法有一个问题:字节只是8位。你说的32位是一个字,或者说是一个基本的管理单元,有4个字节。cpu要读取某一个门牌号的内存,只需要把地址总线设置为相应的门牌号就行。门牌号就在那里,无需存起来。

产生第二个疑惑的根源是你不了解硬件设计和二进制的关系,弥补方法:看一下汇编语言的前三章就可以解决问题。
1