标签:符号 ima image har color cout http mat 负数
#include <iostream> #include <cmath> int main() { unsigned char i = 0 ; i = -1 ; std::cout<<"i="<<(int)i<<std::endl; i = -2 ; std::cout<<"i="<<(int)i<<std::endl; i = -3 ; std::cout<<"i="<<(int)i<<std::endl; i = 256 ; std::cout<<"i="<<(int)i<<std::endl; i = 257 ; std::cout<<"i="<<(int)i<<std::endl; i = 258 ; std::cout<<"i="<<(int)i<<std::endl; std::cout<<"---------------------------"<<std::endl; std::cout<<(int)std::abs(-100)<<std::endl; std::cout<<std::abs(-100.0)<<std::endl; std::cout<<std::abs(-100.0D)<<std::endl; return 0; }
具体原理涉及原码->反码->补码
求绝对值函数abs()有几个重载,传入int,返回值不是int,需要强制转换
标签:符号 ima image har color cout http mat 负数
原文地址:http://www.cnblogs.com/guozhikai/p/6103441.html