CSAPP
Tracy_Jia178
程序妞~
展开
-
对给定值进行操作
题目: Write a C expression that will yield a word consisting of the least significant byte of x, and the remaining bytes of y. For operands x = 0x89ABCDEF and y = 0x76543210, this would give 0x765432E原创 2017-05-01 22:16:30 · 443 阅读 · 0 评论 -
操作系统信息存储与表示
低位存放在高地址,高位存放在低地址。原创 2017-05-01 15:32:31 · 390 阅读 · 0 评论 -
C语言位运算
/* Get most significant byte from x */ int get_msb(int x) { /* Shift by w-8 */ int shift_val = (sizeof(int)-1)<<3; /* Arithmetic shift */ int xright = x >> shift_val; /* Zero all but LSB */ return xrig原创 2017-05-02 15:06:41 · 281 阅读 · 0 评论 -
位运算
#include #include #include /*如果 x 所有位都为 1 ,返回 1 ,否则,返回 0 */ bool x_equals_1(int x) { return !(~x); } /*如果 x 所有位都为 0 ,返回 1 ,否则,返回 0 */ bool x_equals_0(int x) { return !x; } /*如果 x 的最低原创 2017-05-02 20:52:45 · 328 阅读 · 0 评论 -
位运算
#include <stdio.h> #include <stdlib.h> #include <string.h>/* Return 1 when x contains an odd number of 1s; 0 otherwise. Assume w=32. */ int odd_ones(unsigned x){ int y = x; int count_ones = 0;原创 2017-05-02 22:06:17 · 342 阅读 · 0 评论 -
位运算
#include <stdio.h> #include <stdlib.h> #include <string.h>/* * Generate mask indicating leftmost 1 in x. Assume w=32. * For example 0xFF00 -> 0x8000, and 0x6600 --> 0x4000. * If x = 0, then return 0. *原创 2017-05-02 22:24:42 · 265 阅读 · 0 评论