|
|
@ -206,7 +206,9 @@ int allOddBits(int x) { |
|
|
|
* Rating: 2 |
|
|
|
*/ |
|
|
|
int negate(int x) { |
|
|
|
return 2; |
|
|
|
int notx = ~x; |
|
|
|
int res = notx + 1;// since ~x + x = 1111...111 = -1, ~x + x + 1 = 0 |
|
|
|
return res; |
|
|
|
} |
|
|
|
//3 |
|
|
|
/* |
|
|
@ -219,7 +221,12 @@ int negate(int x) { |
|
|
|
* Rating: 3 |
|
|
|
*/ |
|
|
|
int isAsciiDigit(int x) { |
|
|
|
return 2; |
|
|
|
int neg0x3a = ~(0x3a) + 1; |
|
|
|
int neg0x30 = ~(0x30) + 1; |
|
|
|
int signofminus0x3a = (x + neg0x3a) >> 31; // should be all 1 |
|
|
|
int signofminus0x30 = (x + neg0x30) >> 31; // should be all 0 |
|
|
|
int res = !(signofminus0x30 | (~signofminus0x3a)); |
|
|
|
return res; |
|
|
|
} |
|
|
|
/* |
|
|
|
* conditional - same as x ? y : z |
|
|
|