#include <iostream>#include<math.h>using namespacestd;int main () {Charip[ -]; Chartemp[4][4]; CIN>>IP; Char*delim=".";//Separators Char*p; unsignedLongI=3;//It's important to keep the string counter-stored here.strcpy (Temp[i--],strtok (Ip,delim));//The strtok string is split into fragments. The parameter S points to the string to be split, and Delim is the delimiter. while(p=strtok (Null,delim)) {strcpy (temp[i--],p); } unsignedLongarr[4]; unsignedLongstrtemp[4][8]; for(i=0; i<=3; i++)//Convert each string to a number, respectively{Arr[i]=atoi (Temp[i]);//converts the value of a string to an integercout<<arr[i]<<" "; } cout<<Endl; for(i=0; i<=3; i++) { for(unsignedLongj=0; j<=7; j + +)//convert decimal into binary{Strtemp[i][j]=arr[i]%2; Arr[i]=arr[i]/2; cout<<Strtemp[i][j]; } cout<<Endl; } unsignedLongsum=0, result;unsignedLong(*Q) [8]; //here must pay attention to the type of sum, I began to write a long type, the final result is negative, let me debug for a long time!! q=strtemp; unsignedLongCount=0; for(i=0; i<=3; i++) { for(unsignedLongj=0; j<=7; j + +) {result=LDEXP (* (* (q+i) +j), count++); Sum+=result; }} cout<<sum<<Endl; return 0;}
Convert an IP address to an integer