题解 | #整数与IP地址间的转换#

整数与IP地址间的转换

https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea

#include <iostream>
#include <bitset>
using namespace std;

int main() {
    unsigned int a, b, c, d;
    scanf("%d.%d.%d.%d", &a, &b, &c, &d);
    
    unsigned int res = 0;
    res |= a << 24;
    res |= b << 16;
    res |= c << 8;
    res |= d;

    cout << res << endl;

    unsigned int ten;
    cin >> ten;
    cout << ((ten & 0xFF000000) >> 24) << "." << ((ten & 0x00FF0000) >> 16) << "." << ((ten & 0x0000FF00) >> 8) << "." << (ten & 0x000000FF) << endl;

}
// 64 位输出请用 printf("%lld")

我会算吗?我直接就是bit,根本不害怕

全部评论

相关推荐

牛客吹哨人:哨哥晚点统一更新到黑名单:能救一个是一个!26届毁意向毁约裁员黑名单https://www.nowcoder.com/discuss/1525833
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务