Tuesday, April 2, 2013

How to Convert an IP Address to a Number

 To convert an IP address into a number, you can use the following method where each of the four octets of the IP address is multiplied by a power of 2 corresponding to its position:

Formula:

IP Number = (Octet1 * 2^24) + (Octet2 * 2^16) + (Octet3 * 2^8) + (Octet4)

Example: Converting IP Address 46.51.219.242

We can break down the conversion of the IP 46.51.219.242 into a number:

  1. First, separate the octets:

    • Octet1: 46
    • Octet2: 51
    • Octet3: 219
    • Octet4: 242
  2. Apply the formula:

46 * 2^24 = 46 * 16777216 = 771751936 51 * 2^16 = 51 * 65536 = 335544576 219 * 2^8 = 219 * 256 = 56124 242 * 2^0 = 242
  1. Add them together:
771751936 + 335544576 + 56124 + 242 = 775150578

So, the IP address 46.51.219.242 corresponds to the number 775150578.


Class-based IP Addressing:

IP addresses are classified into five classes (A, B, C, D, and E), and each class has a designated range and subnet mask:

ClassLeading BitsStart AddressEnd AddressSubnet Mask
Class A00.0.0.0127.255.255.255/8
Class B10128.0.0.0191.255.255.255/16
Class C110192.0.0.0223.255.255.255/24
Class D1110224.0.0.0239.255.255.255NA
Class E1111240.0.0.0255.255.255.255NA

Explanation of Classes:

  • Class A: Uses addresses from 0.0.0.0 to 127.255.255.255 with a /8 subnet mask, meaning the first 8 bits represent the network part, and the remaining bits represent the host.
  • Class B: Uses addresses from 128.0.0.0 to 191.255.255.255 with a /16 subnet mask, meaning the first 16 bits represent the network part.
  • Class C: Uses addresses from 192.0.0.0 to 223.255.255.255 with a /24 subnet mask, meaning the first 24 bits represent the network part.
  • Class D: Reserved for multicast addresses (224.0.0.0 to 239.255.255.255).
  • Class E: Reserved for experimental purposes (240.0.0.0 to 255.255.255.255).