• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • csapp show-bytes

    發表于:2007-05-26來源:作者:點擊數: 標簽:
    csapp show-bytes /* $begin show-bytes */ #include typedef unsigned char *byte_pointer; void show_bytes(byte_pointer start, int len) { int i; for (i = 0; i len; i++) printf( %.2x, start[i]); printf(\n); } void show_int(int x) { show_bytes((

    csapp show-bytes

    /* $begin show-bytes */
    #include

    typedef unsigned char *byte_pointer;

    void show_bytes(byte_pointer start, int len)
    {
        int i;
        for (i = 0; i < len; i++)
     printf(" %.2x", start[i]);
        printf("\n");
    }

    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 *));
    }
    /* $end show-bytes */


    /* $begin test-show-bytes */
    void test_show_bytes(int val)
    {
        int ival = val;
        float fval = (float) ival;
        int *pval = &ival;
        show_int(ival);
        show_float(fval);
        show_pointer(pval);
    }
    /* $end test-show-bytes */

    void simple_show()
    {
    /* $begin simple-show */
    int val = 0x12345678;
    byte_pointer valp = (byte_pointer) &val;
    show_bytes(valp, 1); /* A. */
    show_bytes(valp, 2); /* B. */
    show_bytes(valp, 3); /* C. */
    /* $end simple-show */
    }

    void float_eg()
    {
    /* $begin float-show */
    int x = 3490593;
    float f = (float) x;
    show_int(x);
    show_float(f);
    /* $end float-show */
    }

    void string_eg()
    {
    /* $begin show-string */
    char *s = "ABCDEF";
    show_bytes(s, strlen(s));
    /* $end show-string */
    }

    void show_twocomp()
    {
    /* $begin show-twocomp */
        short int x = 12345;
        short int mx = -x;
       
        show_bytes((byte_pointer) &x, sizeof(short int));
        show_bytes((byte_pointer) &mx, sizeof(short int));
    /* $end show-twocomp */
    }

    int main(int argc, char *argv[])
    {
        int val = 12345;

        if (argc > 1) {
          if (argv[1][0] == '0' && argv[1][1] == 'x')
     sscanf(argv[1]+2, "%x", &val);
          else
     sscanf(argv[1], "%d", &val);
          printf("calling test_show_bytes\n");
          test_show_bytes(val);
        } else {
          printf("calling show_twocomp\n");
          show_twocomp();
          printf("Calling simple_show\n");
          simple_show();
          printf("Calling float_eg\n");
          float_eg();
          printf("Calling string_eg\n");
          string_eg();
        }
        return 0;
    }

    http://csapp.cs.cmu.edu/

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>