CN_ASSIGNMENT/Practice/1.cpp
// Converts IP address to the binary form
Converts IP address to the binary form
Converts IP address to the binary form
vector<int> bina(vector<string> str)
	{
	vector<int> re(32,0);
		int a, b, c, d, i, rem;
		a = b = c = d = 1;
		stack<int> st;
			a = stoi(str[0]);
			b = stoi(str[1]);
			c = stoi(str[2]);
			d = stoi(str[3]);
		for (i = 0; i <= 7; i++)
		{
			rem = a % 2;
			st.push(rem);
			a = a / 2;
		}
		for (i = 0; i <= 7; i++) {
			re[i] = st.top();
			st.pop();
		}
		for (i = 8; i <= 15; i++) {
			rem = b % 2;
			st.push(rem);
			b = b / 2;
		}
		for (i = 8; i <= 15; i++) {
			re[i] = st.top();
			st.pop();
		}
		for (i = 16; i <= 23; i++) {
			rem = c % 2;
			st.push(rem);
			c = c / 2;
		}
		for (i = 16; i <= 23; i++) {
			re[i] = st.top();
			st.pop();
		}
		for (i = 24; i <= 31; i++) {
			rem = d % 2;
			st.push(rem);
			d = d / 2;
		}
		for (i = 24; i <= 31; i++) {
			re[i] = st.top();
			st.pop();
		}
		return (re);
	}
vector < int > bina ( vector < string > str ) { vector < int > re ( 32 , 0 ) ; int a , b , c , d , i , rem ; a = b = c = d = 1 ; stack < int > st ; a = stoi ( str [ 0 ] ) ; b = stoi ( str [ 1 ] ) ; c = stoi ( str [ 2 ] ) ; d = stoi ( str [ 3 ] ) ; for ( i = 0 ; i <= 7 ; i ++ ) { rem = a % 2 ; st . push ( rem ) ; a = a / 2 ; } for ( i = 0 ; i <= 7 ; i ++ ) { re [ i ] = st . top ( ) ; st . pop ( ) ; } for ( i = 8 ; i <= 15 ; i ++ ) { rem = b % 2 ; st . push ( rem ) ; b = b / 2 ; } for ( i = 8 ; i <= 15 ; i ++ ) { re [ i ] = st . top ( ) ; st . pop ( ) ; } for ( i = 16 ; i <= 23 ; i ++ ) { rem = c % 2 ; st . push ( rem ) ; c = c / 2 ; } for ( i = 16 ; i <= 23 ; i ++ ) { re [ i ] = st . top ( ) ; st . pop ( ) ; } for ( i = 24 ; i <= 31 ; i ++ ) { rem = d % 2 ; st . push ( rem ) ; d = d / 2 ; } for ( i = 24 ; i <= 31 ; i ++ ) { re [ i ] = st . top ( ) ; st . pop ( ) ; } return ( re ) ; }
Converts IP address to the binary form
Converts IP address to the binary form
// Separate each number of the IP address // convert first number to binary // Obtain First octet // convert second number to binary // Obtain Second octet // convert Third number to binary // Obtain Third octet // convert fourth number to binary // Obtain Fourth octet