/*
* Name: IP Address
* Funcion: To convert binary numbers to decimal numbers
* Input: 00000011100000001111111111111111
* Output: 3.128.255.255
*/
#include <stdio.h>
void main()
{
char input[32];
int output[4];
int count = -1;
for(int i = 0; i < 4; i++ )
output[i] = 0;
gets( input );
for( i = 0; i < 32; i++ )
{
if( i % 8 == 0 )
count++;
if( input[i] == '1' )
{
switch( i % 8 )
{
case 0:
output[count] += 128;
break;
case 1:
output[count] += 64;
break;
case 2:
output[count] += 32;
break;
case 3:
output[count] += 16;
break;
case 4:
output[count] += 8;
break;
case 5:
output[count] += 4;
break;
case 6:
output[count] += 2;
break;
case 7:
output[count] += 1;
break;
default:
break;
}
}
}
printf( "%d.%d.%d.%d\n", output[0], output[1], output[2], output[3] );
}
posted on 2007-03-04 10:05
周Q 阅读(4249)
评论(3) 编辑 收藏 引用