CN_ASSIGNMENT/Practice/1.cpp
// Converts IP address
// from binary to decimal form
Converts IP address
from binary to decimal form
Converts IP address from binary to decimal form
vector<int> deci(vector<int> bi)
	{
		vector<int> arr(4,0);
		int a, b, c, d, i, j;
		a = b = c = d = 0;
		j = 7;
		for (i = 0; i < 8; i++) {
			a = a + (int)(pow(2, j)) * bi[i];
			j--;
		}
		j = 7;
		for (i = 8; i < 16; i++) {
			b = b + bi[i] * (int)(pow(2, j));
			j--;
		}
		j = 7;
		for (i = 16; i < 24; i++) {
			c = c + bi[i] * (int)(pow(2, j));
			j--;
		}
		j = 7;
		for (i = 24; i < 32; i++) {
			d = d + bi[i] * (int)(pow(2, j));
			j--;
		}
		arr[0] = a;
		arr[1] = b;
		arr[2] = c;
		arr[3] = d;
		return arr;
	}
vector < int > deci ( vector < int > bi ) { vector < int > arr ( 4 , 0 ) ; int a , b , c , d , i , j ; a = b = c = d = 0 ; j = 7 ; for ( i = 0 ; i < 8 ; i ++ ) { a = a + ( int ) ( pow ( 2 , j ) ) * bi [ i ] ; j -- ; } j = 7 ; for ( i = 8 ; i < 16 ; i ++ ) { b = b + bi [ i ] * ( int ) ( pow ( 2 , j ) ) ; j -- ; } j = 7 ; for ( i = 16 ; i < 24 ; i ++ ) { c = c + bi [ i ] * ( int ) ( pow ( 2 , j ) ) ; j -- ; } j = 7 ; for ( i = 24 ; i < 32 ; i ++ ) { d = d + bi [ i ] * ( int ) ( pow ( 2 , j ) ) ; j -- ; } arr [ 0 ] = a ; arr [ 1 ] = b ; arr [ 2 ] = c ; arr [ 3 ] = d ; return arr ; }
Converts IP address
from binary to decimal form
Converts IP address from binary to decimal form