IP ADDRESS

Program in C++ to convert 32 bit ip address from decimal notation to h

Page 1 of 1

1 Replies - 6321 Views - Last Post: 26 March 2008 - 11:01 PM Rate Topic: -----

#1 sumit_bhutaniin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-March 08

IP ADDRESS

Post icon  Posted 26 March 2008 - 10:56 PM

#include <iostream.h>

main()
{
// Initialize the variables
unsigned long a,b,c,d,base10IP;

// Get the IP address from user
cout << "\nEnter an IP address in dotted quad notation (x.x.x.x)";
cout << "\nwith each section seperated by a space: ";
cin >> a >> b >> c >> d;

// Do calculations to covert IP to base 10
a *= 16777216;
b *= 65536;
c *= 256;
base10IP = a + b + c + d;

// Output new IP address
cout << "\nThe converted address is: " << base10IP << '\n';
}


this is the following code which i could manage to figure out, please help me to convert this from decimal to hexa also if possible please send me a C++ program to convert hexadecimal notation to decimal notation

Is This A Good Question/Topic? 0
  • +

Replies To: IP ADDRESS

#2 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5174
  • View blog
  • Posts: 26,864
  • Joined: 10-May 07

Re: IP ADDRESS

Posted 26 March 2008 - 11:01 PM

...2nd result on Google searching "convert decimal to hex".
int main() {
char outStr[256];
int inDec = 65535;
sprintf(outStr,"%x",inDec);
printf("%d in hex is %s\n",inDec,outStr);
}



Quote

also if possible please send me a C++ program

No one is going to give you a program. We will do our best to help you out, & answer questions, but we don't give out programs here, sorry.

:code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1