打开VC++6.0
点击,文件,新建
填写工程名字,选择C++ source file
这样就创建了一个空白工作区
首先,我们要写需要的头文件#include
之后,按格式写主函数
之后,我们必须声明要用到的变量 unsigned long input_IP;unsigned int BeginByte,MidByte,ThirdByte,EndByte;unsigned int_rotate=0x07;
下面是主要代码 printf('请输入你需要解析的IP地址:');scanf('%lx',&input_IP);BeginByte = (input_IP >> 24) & ~(~0 << 8);//获取IP地址最高位MidByte = (input_IP >> 16) & ~(~0 << 8);//获取第二段ThirdByte = (input_IP >> 8 ) & ~(~0 << 8);//获取第三段EndByte = input_IP & ~(~0 << 8);//获取第四段printf('The IP address after parsed is: %d.%d.%d.%d\n',BeginByte,MidByte,ThirdByte,EndByte);/*两个循环移位函数*/ printf('%u after rotated twice is =%u\n',int_rotate,_rotl(int_rotate,2)); printf('%u after rotated once is =%u\n',int_rotate,_rotr(int_rotate,1)); _rotl _rotr利用左移和右移函数,输出,可以确保信息不丢失
完成后点击编译和执行
程序运行
输入IP地址,后回车