2008년 04월 16일
2008년 1학기 시스템 프로그래밍 - isZero
isZero.
이것은 인자로 들어온 x가 0이면 1을 0이 아니면 0을 반환합니다.
쓸 수 있는 명령어 중 !이 있기에 !으로 해결하였습니다.
/*
* isZero - returns 1 if x == 0, and 0 otherwise
* Examples: isZero(5) = 0, isZero(0) = 1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 2
* Rating: 1
*/
int isZero(int x) {
/* if a is zero, then !a is 1. if a is nonzero, then !a is 0.
*
* 20080401
*/
return !x; // 0 == x -> x = 1, 0 != x -> x = 0
}
# by | 2008/04/16 12:28 | in Lesson | 트랙백 | 핑백(1) | 덧글(0)















☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
... '2008년 1학기 시스템 프로그래밍 - bitOr' '2008년 1학기 시스템 프로그래밍 - isLessOrEqual' '2008년 1학기 시스템 프로그래밍 - isZero' '2008년 1학기 시스템 프로그래밍 - log2' '2008년 1학기 시스템 프로그래밍 - logicalNeg' '2008년 1학기 시스템 프로그래밍 ... more