c언어 함수 설명부탁드립니다! 7

글쓴이: 익명 사용자 / 작성시간: 일, 2019/10/06 - 6:19오후
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | /* * leftBitCount - returns count of number of consective 1's in * left-hand (most significant) end of word. * Examples: leftBitCount(-1) = 32, leftBitCount(0xFFF0F0F0) = 12 * Legal ops: ! ~ & ^ | + << >> * Max ops: 50 * Rating: 4 */ int leftBitCount(int x) { int temp=x; int result; int shift; int one =!(~x); result = !(~(temp>>16))<<4; temp=temp<<result; shift=!(~(temp>>24))<<3; temp=temp<<shift; result=result|shift; shift=!(~(temp>>28))<<2; temp=temp<<shift; result=result|shift; shift=!(~(temp>>30))<<1; temp=temp<<shift; result=result|shift; result=result^(1&((temp>>31))); return result+one; } /* * isTmin - returns 1 if x is the minimum, two's complement number, * and 0 otherwise * Legal ops: ! ~ & ^ | + * Max ops: 10 * Rating: 1 */ int isTmin(int x) { return !((x^(~x+1))+!x); } /* * fitsBits - return 1 if x can be represented as an * n-bit, two's complement integer. * 1 <= n <= 32 * Examples: fitsBits(5,3) = 0, fitsBits(-4,3) = 1 * Legal ops: ! ~ & ^ | + << >> * Max ops: 15 * Rating: 2 */ int fitsBits(int x, int n) { int y=x>>(n+(~0)); return (!(y+1)) | (!y); } /* * sign - return 1 if positive, 0 if zero, and -1 if negative * Examples: sign(130) = 1 * sign(-23) = -1 * Legal ops: ! ~ & ^ | + << >> * Max ops: 10 * Rating: 2 */ int sign(int x) { return((!!x)|(x>>31)); } /* * isNotEqual - return 0 if x == y, and 1 otherwise * Examples: isNotEqual(5,5) = 0, isNotEqual(4,5) = 1 * Legal ops: ! ~ & ^ | + << >> * Max ops: 6 * Rating: 2 */ int isNotEqual(int x, int y) { return !(!(x^y)); } | cs |
File attachments:
첨부 | 파일 크기 |
---|---|
![]() | 11.71 KB |
Forums:
c언어 이제 배우기 시작해서 하나도 모르겠어요ㅠ
총 5개함수 설명부탁드립니다. c언어 이제 시작해서 코드 이해하기가 어렵네요ㅠㅠ
CS:APP(http://csapp.cs.cmu
CS:APP(http://csapp.cs.cmu.edu)의 Data lab이군요.
그 책 좋은 책이니까 앞에서부터 천천히 공부해 보시면 이해할 수 있게 될 겁니다.
댓글 달기