기본 지식 포인트
IP-> 정수 :
IP 주소를 왼쪽 시프트 (<<), (&), 또는 (|) int to int로 (|)를 통해 바이트 배열로 변환합니다.
정수-> IP :
오른쪽 시프트 작동 (>>>) 오른쪽을 24 비트로 전환 한 다음 획득 한 숫자는 첫 번째 IP입니다.
오른쪽 시프트 작동 (>>>)은 16 비트를 오른쪽으로 바꾸고 연산자 (&) 0xff를 수행합니다.
오른쪽 시프트 작동 (>>>), 8 비트의 오른쪽으로 이동 한 다음, 획득 한 숫자는 세 번째 세그먼트 IP입니다.
정수 값은 연산자 (&) 0xff와 함께 수행되며, 얻은 숫자는 네 번째 단계 IP입니다.
생각
예를 들어 IP 주소는 "192.168.1.116"이며 "IP 주소를 4 개의 부품으로 나누고 각 부품의 해당 전력 값은 256^3, 256^2입니다. 256, 1, 그리고 복잡 할 때 가능한 빨리
int type to ip 주소, 중량 값을 제외하고 유사한 아이디어이지만 일부 문자열 작업
암호
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define len 16 typedef unsigned int uint (char *ipstr) {iftr == null ) char token i = 3, cur (ipstr); = 0 && cur <= 255) {Total += cur*pow (256, i);} i-; (char*str, int begin, int end) {int i, j; (str [i]! i] ^ str [j];}}} / *** Ipstan String* / char*iptstr (char*new = (char*) malloc (len); ); char 토큰; strcat (새로운, 토큰); = 0; ed <len && new [ed]! } new [len-1] = '/0'; "%s"%s scanf ( "%s s"%s scanf ( "%s s"%s scanf ( "%s"%s scanf ( "%s s.", ipstr)! = eof) {iptint (ipstr) ( "%u/n", ipint);