Hello, I have a problem solving a similar problem..It is about IPv4.
I have to create a program in C that we will give as an input the IP address and the subnet mask in dotted decimal form and it will provide in the output
a) the network address in decimal, binary and hexadecimal form,
b) the host address in decimal, binary and hexadecimal form.
Here is the code I have written until now. Any help would be higly appreciated.


#include <stdio.h>
#include <stdlib.h>

int i=0, j, a, b, c;
int decimal;
int g[]={0}, k[]={0};

//decimal to binary
int dectobin(a) {
i=0;
do {
decimal=a%2;
g[i]=decimal;
i++;
a=a/2;
}while (a>0);


for (j=i-1;j>=0;j--) {
printf("%d",g[j]);
}
}

//decimal to hexadecimal
int dectohex(b) {
i=0;
do {
decimal=b%16;
k[i]=decimal;
i++;
b=b/16;
}while (b>0);


for (j=i-1;j>=0;j--) {
printf("%X",k[j]);
}
}


//binary to decimal
int bintodec(char *bin) {
i=0;
// don't know how to do it!
}



int main()
{

int x,y,z,w; // for the IP
int l,m,n,p; // for the subnet mask

printf("Please enter your IP Address with each section:\n");
printf("seperated by a space: ");
scanf("%d%d%d%d",&x,&y,&z,&w);

while ( (x>255)||(x<0)||(y>255)||(y<0)||(z>255)||(z<0)||(w >255)||(w<0) ) {
printf("IP Address not valid! Re-enter:\n ");
scanf("%d %d %d %d",&x,&y,&z,&w);
}


printf("Your IP Address is: %d.%d.%d.%d",x,y,z,w);
printf("\n\n");

printf("Please enter your subnet mask:\n");
scanf("%d %d %d %d",&l,&m,&n,&p);
// IP class A with the first octet of the subnet 255.xxx.xxx.xxx
if ( (x>=0)&&(x<=127) ) {
while ( (l!=255) ) {

printf("subnet mask invalid! Re-enter:\n");
scanf("%d %d %d %d",&l,&m,&n,&p);
}

//Network Address for class A
// dotted decimal
//binary
//hexadecimal
printf("\n");


//Host Address for class A

// in dotted decimal

// in binary

//in hexadecimal

// IP class B
else if ( (x<=191) ) {
//IP address
printf("Your IP Address belongs to Class B.\n");
//Network address for B
//in decimal, binary, hexadecimal


// IP class C
else if (x<=223) {
//IP address
printf("Your IP Address belongs to Class C.\n");
//Network address

//Host address

// IP class D
else if(x<=239) {
//IP address
printf("Your IP Address belongs to Class C.\n");
{
printf("Your IP Address belongs to Class D.\n");
printf("This class of IPs is reserved for multicasting purposes.\n");
}


// IP class D
else {
//IP address

printf("Your IP Address belongs to Class E.\n");
printf("This class of IPs is reserved for testing purposes.\n");
}



printf("\n\n\n");

system("pause");

}