cs app lab1 深入理解计算机系统

本文提供了几个关于计算机系统操作的练习题,包括使用位运算实现特定逻辑操作的函数,如bitAnd、bitXor、thirdBits等,并探讨了如何判断数值是否能用n位二进制补码表示、数值的符号判断以及字节提取等问题。每个函数都有相应的解决方案和解释。
摘要由CSDN通过智能技术生成
#include <iostream>
// Rating: 1  
/*  
 * bitAnd - x&y using only ~ and |  用~和|表示& 
 *   Example: bitAnd(6, 5) = 4  0110 0101
 *   Legal ops: ~ | 
 *   Max ops: 8 
 *   Rating: 1 
 */  
int bitAnd(int x, int y) {  
  return ~(~x|~y);  
}  
/*  
 * bitXor - x^y using only ~ and &  用~和&表示^ 
 *   Example: bitXor(4, 5) = 1 
 *   Legal ops: ~ & 
 *   Max ops: 14 
 *   Rating: 1 
 */  
int bitXor(int x, int y) {  
  return ~(x&y)&~(~x&~y);  
}  
/*  
 * thirdBits - return word with every third bit (starting from the LSB) set to 1 
 * 从左到右每三个位有一个1 
 *   Legal ops: ! ~ & ^ | + << >> 
 *   Max ops: 8 
 *   Rating: 1 
 */  
int thirdBits(void) { 
int result = 0x24;
 result = (result << 8) + 0x92;
 result = (result << 8) + 0x49;
 result = (result << 8) + 0x24;
 return result;
  return 2;  
}  
// Rating: 2  
/*  
 *
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值