int abs(int v) { int t = v >> 31;//取符号位,整数为0,负数为-1 return (v^t) - t;//整数异或0本身;负数异或-1取反+1就是绝对值 } 转载于:https://www.cnblogs.com/jecyhw/p/4369044.html