Esempio n. 1
0
int threefourths(int x) {
	int w = sizeof(x) << 3;
	int sx = x >> (w - 1); // all 0(s) or all 1(s)
	int mod4 = x & 3;

	int need_bias = (!sx && mod4 == 3) || (sx && mod4 == 1);
	int neg_bias = (need_bias & sx) << (w - 1) >> (w - 1); // 0(s) or 1(s)
	int pos_bias = need_bias; // 0 or 1
	int bias = neg_bias | pos_bias;

	return divide_power2(x, 1) + divide_power2(x, 2) + bias;
}
Esempio n. 2
0
int main() {

	int x, k;
	
	printf(" x = ");
	scanf("%d", &x);
	printf(" k = ");
	scanf("%d", &k);

	printf("\n RESULT = %d \n", divide_power2(x, k));
	
	return 0;

}