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

文远知行公司福利 580人发布