3,881
社区成员
发帖
与我相关
我的任务
分享
int bin_dec(const int & x, const int & n)
{
if (n == 0)
return 1;
return x*bin_dec(x, n - 1);
}
int bin_dec(int&&x, int&&n)
{
if (n == 0)
return 1;
return x*bin_dec(std::forward<int>(x), n - 1);
}
#include<stdio.h>
#include <tchar.h>
int bin_dec(int &x, int &n)
{
int i;
if (n == 0)
return 1;
i = n - 1;
return x*bin_dec(x, i);
}
int _tmain(int argc, _TCHAR* argv[])
{
int i, j;
int ip[4] = { 0 };
char a[33];
int c = 2, b = 7,d = 15,e = 23,f = 31;
printf("输入二进制数:\n");
scanf_s("%s", a,33);
for (i = 0; i < 8; i++)
{
if (a[i] == '1')
{
j = b - i;
ip[0] += bin_dec(c, j);
}
}
for (i = 8; i < 16; i++)
{
if (a[i] = '1')
{
j = d - i;
ip[1] += bin_dec(c, j);
}
}
for (i = 16; i < 24; i++)
{
j = d - i;
if (a[i] == '1')
{
j = d - i;
ip[2] += bin_dec(c, j);
}
for (i = 24; i < 32; i++)
{
if (a[i] == '1')
{
j = f - i;
ip[3] += bin_dec(c, j);
}
if (a[i] == '\0')
break;
}
printf("IP:\n");
printf("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
}
}