有符号数与无符号数之间的转换

long long unsigned intToUnsigned (const int& i)
{
    return static_cast<long long unsigned>(i >= 0 ? i : (i + pow (2.0, 32.0)));
}

int UnsignedToInt (const long long unsigned& u)
{
    auto limit = static_cast<long long unsigned>(pow(2.0, 32.0));
    return static_cast<int>(limit < u? (u - limit) : u); 
}

 

posted @ 2015-05-29 22:31  wu_overflow  阅读(291)  评论(0编辑  收藏  举报