标签:blog io div 2014 log ef amp as size
#include<stdio.h> #define debug_print(x) printf(#x"\t%d\n",x) int divide_power2(int x,int k) { int w = sizeof(int) << 3; int sign = x >> (w - 1) ; int result; ( sign == 0 && (result = (x >> k)) ) || ( sign == -1 && (result = ((x + (1 << k)-1)>> k)) ); return result; } int main() { debug_print(100>>3); debug_print(divide_power2(100,3)); debug_print(-100>>3); debug_print(divide_power2(-100,3)); return 0; }
标签:blog io div 2014 log ef amp as size
原文地址:http://blog.csdn.net/u012769069/article/details/41874047