• 2018-2019-1 20165324 《信息安全系统设计基础》第三周课堂练习


    2018-2019-1 20165324 《信息安全系统设计基础》第三周课堂练习

    任务一

    1. 调用附图代码,编写一个程序“week0202学号.c",用show_int(),show_float()打印一下你的4位学号,参考教材P33打印出匹配的位序列。
    2. 提交运行结果截图,要全屏,要包含自己的学号信息
    3. 课下把代码推送到代码托管平台
    4. 参考教材p82,给出出匹配的位序列的推导过程
    5. 代码及截图如下:
    #include <stdio.h>
    typedef unsigned char *byte_pointer;
    void show_bytes(byte_pointer start,size_t len)
    {
        size_t i;
        for (i=0;i<len;i++)
            printf("%.2x",start[i]);
        printf("
    ");
    }
    void show_int (int x)
    {
        show_bytes((byte_pointer) &x,sizeof(int));
    }
    void show_float(float x)
    {
        show_bytes((byte_pointer) &x,sizeof(float));
    }
    void show_pointer(void *x)
    {
        show_bytes((byte_pointer) &x,sizeof(void *));
    }
    void test_show_bytes(int val)
    {
        int ival=val;
        float fval=(float)val;
        int  *pval = &ival;
        show_int(ival);
        show_float(fval);
        show_pointer(pval);
    }
    main()
    {
    char c=0x12345678;
    show_int(c);
    if(c==0x12)
    printf("20155337是大端
    ");
    else
    printf("20155337是小端
    ");
    

    实践二

    1. 调用附图代码,编写一个程序 “week0602学号.c",用show_int(), show_float()打印一下你的4位学号,参考教材P33打印出匹配的位序列。
    2. 提交运行结果截图,要全屏,要包含自己的学号信息
    3. 代码及截图如下:
    #include <stdio.h>
    typedef unsigned char *byte_pointer;
    void show_bytes(byte_pointer start,size_t len)
    {
        size_t i;
        for (i=0;i<len;i++)
            printf("%.2x",start[i]);
        printf("
    ");
    }
    void show_int (int x)
    {
        show_bytes((byte_pointer) &x,sizeof(int));
    }
    void show_float(float x)
    {
        show_bytes((byte_pointer) &x,sizeof(float));
    }
    void show_pointer(void *x)
    {
        show_bytes((byte_pointer) &x,sizeof(void *));
    }
    void test_show_bytes(int val)
    {
        int ival=val;
        float fval=(float)val;
        int  *pval = &ival;
        show_int(ival);
        show_float(fval);
        show_pointer(pval);
    }
    int main()
    {
        int x=5337;
        test_show_bytes(x);
    }
    

    任务三

    1. 编写一个程序 “week0203学号.c",运行下面代码:
    1   short int v = -学号后四位
    2   unsigned short uv = (unsigned short) v
    3  printf("v = %d,  uv = %u
     ", v, uv);
    
    1. 在第三行设置断点用gdb调试,用p /x v; p /x uv 查看变量的值,提交调试结果截图,要全屏,要包含自己的学号信息

    2. 分析p /x v; p /x uv 与程序运行结果的不同和联系

    3. 代码及截图如下:

    #include <stdio.h>
    typedef unsigned char *byte_pointer;
    void show_bytes(byte_pointer start,size_t len)
    {
        size_t i;
        for (i=0;i<len;i++)
            printf("%.2x",start[i]);
        printf("
    ");
    }
    void show_int (int x)
    {
        show_bytes((byte_pointer) &x,sizeof(int));
    }
    void show_float(float x)
    {
        show_bytes((byte_pointer) &x,sizeof(float));
    }
    void show_pointer(void *x)
    {
        show_bytes((byte_pointer) &x,sizeof(void *));
    }
    void main()
    {
    short int v = -学号后四位
    
    unsigned short uv = (unsigned short) v
    
    printf("v = %d, uv = %u
     ", v, uv);
    }
    
  • 相关阅读:
    Why Visual Studio Team System Isn't A LoadRunner Killer[转载]
    从键盘判断电脑主人
    LoadRunner中添加weblogic监视器(JMX)
    winrunner事务概念的代码应用(毫秒级)
    Delphi中的线程类
    换工作时如何提高自身的待遇(转贴)
    牛人是怎样用函数实现本地化测试的
    肯德基的见闻
    由 12306.cn 谈谈网站性能技术
    20个优秀的 CSS 网格系统(CSS Grid Systems)推荐
  • 原文地址:https://www.cnblogs.com/20165324hcj/p/9771537.html
Copyright © 2020-2023  润新知