Method of mutual conversion between IP and integer in Java

This paper describes the method of mutual conversion between IP and integer in Java. Share with you for your reference. The specific analysis is as follows:

1、 Basic knowledge points

IP ― > integer: convert the IP address into a byte array and convert it into an int integer through left shift (< >), and (&), or (|). IP: shift the integer value to the right (> > >), shift it to the right by 24 bits, and then carry out the and operator (&) 0xff. The number obtained is the first segment of IP. Shift the integer value to the right (> > >), shift 16 bits to the right, and then perform the and operator (&) 0xff to obtain the second segment IP. Shift the integer value to the right (> > >), shift 8 bits to the right, and then perform the and operator (&) 0xff to obtain the third segment IP. Combine the integer value with the operator (&) 0xff to obtain the fourth segment IP.

2、 Java code example (ipv4util. Java)

I hope this article will be helpful to your Java programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>