왜이렇게되는지모르겠네요~
모람
질문 제목 : 비트연산관련
질문 내용 :
/*
* ispower2 - returns 1 if x is a power of 2, and 0 otherwise
* examples: ispower2(5) = 0, ispower2(8) = 1, ispower2(0) = 0
* note that no negative number is a power of 2.
* legal ops: ! ~ & ^ | +
*/
int ispower2(int x) {
return 2;
}
/*
* minusone - return a value of -1
* legal ops: ! ~ & ^ | +
* max ops: 2
*/
int minusone(void) {
return ((0x0131)31);
}
/*
* replacebyte(x,n,c) - replace byte n in x with c
* bytes numbered from 0 (lsb) to 3 (msb)
* examples: replacebyte(0x12345678,1,0xab) = 0x1234ab78
* you can assume 0 = n = 3 and 0 = c = 255
* legal ops: ! ~ & ^ | +
* max ops: 10
*/
int replacebyte(int x, int n, int c) {
x=x&(~(0xff(n3)));
c=c(n3); return x+c;
}
첫번째문제는2의멱승을구하는건데요
return (~x+1)31을했는데잘안되더라구요..
두번째문제와세번째문제는왜리턴값을이렇게지정했는지모르겠네요
가르쳐주시면감사하겟습니다.