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

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

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 @   靖意风  Views(8)  Comments(0Edit  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示