Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week2: 信息的表示与处理 #2

Open
OhBonsai opened this issue Sep 24, 2020 · 0 comments
Open

Week2: 信息的表示与处理 #2

OhBonsai opened this issue Sep 24, 2020 · 0 comments
Labels
CSAPP 深入理解计算机系统

Comments

@OhBonsai
Copy link
Owner

OhBonsai commented Sep 24, 2020

信息存储

字数据大小

  • 每台计算机有一字长,指针数据的标称大小。字长决定虚拟地址控件大小0~2^w-1
--------------------------------------------
|            c声明             |  字节数   |
--------------------------------------------
|  有符号     |     无符号     |32位 | 64位|
--------------------------------------------
|  char       | unsigned char  |  1  |  1  |
--------------------------------------------
|  short      | unsigned short |  2  |  2  |
--------------------------------------------
|  int        |  unsigned      |  4  |  4  |
--------------------------------------------
|  long       | unsigned long  |  4  |  8  |
--------------------------------------------
| int32_t     | uint32_t       |  4  |  4  |
--------------------------------------------
| int64_t     | uint64_t       |  8  |  8  |
--------------------------------------------
| char *      |                |  4  |  8  |
--------------------------------------------
| float       |                |  4  |  4  |
--------------------------------------------
| double      |                |  8  |  8  |
--------------------------------------------

面试问题

为什么计算机用补码表示整数,而不是反码或者原码

上学时候老师讲补码都是对某个值的原码求反加1. 比如+2010,那么-2就是101 + 1 == 110。可是补码的这个代表什么呢?其实

-2 = 2^3 - 2 

上面-23个bit表示,补码表达的就是补充到2^ 3需要的值的大小
csapp里面给出了使用补码带来的两个好处

  1. +0-0在补码的表示中都是00,这带来了一致性。另外可以表达-128
  2. 在做加法的时候不需要考虑符号位,因为减法是表示一个数加一个数的负数。 比如+1 -3, 相当于 0001 + 1101 = 1110。也就是-2
@OhBonsai OhBonsai added the CSAPP 深入理解计算机系统 label Sep 24, 2020
@OhBonsai OhBonsai added this to the 读书会:CSAPP milestone Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSAPP 深入理解计算机系统
Projects
None yet
Development

No branches or pull requests

1 participant