昨天纠正了长达几年的关于字节序的错误理解。 受到移位操作符的影响,一直认为在内存中数字的保存方式和显示的一样,比如一个2直接的short 9 ,保存在内存中应该是: 00 09 这种形式,因为这样移位才说的通。 否则如果按照低字节优先的方法 09 00 右移位就会出乱子了~ 结果昨天研究和服务器socket通讯的例子中 发现了个陌生函数 :htonl 。 man (越来越喜欢命令行了)后发现是 host to network long(short) 的缩写 ,这下彻底困惑了。难道 c 在内存中的数据不是想象中的那样? 最后K大侠亲自上阵,示范了使用GDB debug ,也帮我验证了我多年的错误观点: #include <stdio.h> int main() { int a = 8; char *p; p= (char*)&a; a = a>>1; char *k = &a; return 0; } gcc -g test.c # …
-
Pages
-
Recent Posts
-
Recent Comments
- xhan: 哇开源项目,赶紧收藏了。
- Du Song: 建议看下Fluid / Fluidium,封装网页应用很方便,功能也比较多。
- Johnkf: One of my friends already told me about this place and I do not regret that I found this article.
- reobsete-online: Many thanks.
- Ken Chung: I am developing an iPhone/iPad app. Would you be interested in helping me? I’m based in Shanghai. My...