首页 > 其他 > 详细

由数字转换到子网掩码

时间:2020-05-03 23:48:36      阅读:113      评论:0      收藏:0      [点我收藏+]

https://blog.csdn.net/u012258978/article/details/54022480

// testconv.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <cstring>
#include <stdio.h>
#include<stdlib.h>
#include <iostream>
#include <string>
#define LMOVE(m,n) ((m)<<(n))
#define RMOVE(m,n) ((m)>>(n))

using namespace std;
#ifdef WIN32
#define snprintf _snprintf
#endif
static std::string convert(int n)
{
	char buf[32] = {0};
	unsigned int addr = LMOVE(0xffffffff,32 - n);
	snprintf(buf, sizeof(buf), "%u.%u.%u.%u",
		RMOVE(addr,24), RMOVE(addr,16)&0xff, RMOVE(addr,8)&0xff, addr&0xff);
	return buf;
}
int _tmain(int argc, _TCHAR* argv[])
{
	int pnum = 252;
	string str11 = convert(pnum);
	std::cout<<str11<<std::endl;
	system("PAUSE");
	return 0;
}

  

由数字转换到子网掩码

原文:https://www.cnblogs.com/hshy/p/12824476.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!