《深入理解计算机基础》初步学习

记录《深入理解计算机基础》相关的网站:

https://csapp.cs.cmu.edu csapp 的官方网站
https://csapp.cs.cmu.edu/public/code.html 下载代码的网站
https://blog.csdn.net/weixin_43362650/article/details/122893339 大牛的学习总结分享
https://live.eyunbo.cn/live/62010?uin=1729 // 大学教师 直播讨论分享

1. 变量地址的最低字节地址 表示该变量地址。小端格式是 低地址存放低字节

2. C代码打印指定数值的各位数值

$cat 1.c
#include <stdio.h>
void show_bits(unsigned long val, int size)
{
    int ix = 0;
    for (ix=0; ix < 8*size; ix++)
    {
        printf("%ld ", val&0x01);
        val = val >> 1;
    }
    printf("\n");
}

void main() 
{
    short a = 12345;
    unsigned short b = 53191;

    printf("a=%7d ", a);
    show_bits(a, sizeof(a));

    a = -12345; 
    printf("a=%7d ", a);
    show_bits(a, sizeof(a));

    printf("a=%7u ", b);
    show_bits(b, sizeof(b));
}
$
$ ./a.out 
a=  12345 1 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 
a= -12345 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 
a=  53191 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1
View Code

 

posted @ 2024-07-15 11:05  靖意风  Views(15)  Comments(0)    收藏  举报