CSApp lab--datalab

2019-09-29  本文已影响0人  lucasgao

简介

这个实验的目的是为了让大家对 位表示的整型和浮点数有进一步的认识。
大家需要解决一些 puzzles,并从中得到自己的思考。

The purpose of this assignment is to become more familiar with bit-level representations of integers and floating point numbers. You’ll do this by solving a series of programming “puzzles.” Many of these puzzles are quite artificial, but you’ll find yourself thinking much more about bits in working your way through them.

题目本身不难,但是这里限定了我们可以使用的运算符号只有以下8个
! ̃ & ˆ | + << >>

解答

1. bit xor

//1
/* 
 * 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 2;
}

QA

1. 编译报错

image.png
执行命令
apt-get install gcc-multilib
上一篇下一篇

猜你喜欢

热点阅读