题解 | #整数与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,根本不害怕

全部评论

相关推荐

Minamotoek...:你这个简历,看一眼就感觉很乱,而且还写什么羽毛球教练和训练教官之类的,感觉和你要投的岗位很不相干
投递前程无忧等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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