Post History
Task Given an IP address as a string, find its IP address class. For reference, here is a table: Class Leadingbits Numberof networks Addressesper network Total addressesin class Start...
Question
code-golf
#2: Post edited
Find the IP address class
- # Task
- Given an IP address as a string, find its [IP address class.](https://www.guru99.com/ip-address-classes.html)
- For reference, here is a table:
- <table class="wikitable" style="width: 855px;">
- <tbody>
- <tr>
- <th style="width: 92px;">Class</th>
- <th style="width: 45px;">Leading<br>bits</th>
- <th style="width: 175px;">Number<br>of networks</th>
- <th style="width: 160px;">Addresses<br>per network</th>
- <th style="width: 29px;">Total addresses<br>in class</th>
- <th style="width: 43px;">Start address</th>
- <th style="width: 146px;">End address</th>
- </tr>
- <tr>
- <td style="width: 92px;">Class A</td>
- <td style="width: 45px;">0</td>
- <td style="width: 175px;">128 (2<sup>7</sup>)</td>
- <td style="width: 160px;">16,777,216 (2<sup>24</sup>)</td>
- <td style="width: 29px;">2,147,483,648 (2<sup>31</sup>)</td>
- <td style="width: 43px;">0.0.0.0</td>
- <td style="width: 146px;">127.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class B</td>
- <td style="width: 45px;">10</td>
- <td style="width: 175px;">16,384 (2<sup>14</sup>)</td>
- <td style="width: 160px;">65,536 (2<sup>16</sup>)</td>
- <td style="width: 29px;">1,073,741,824 (2<sup>30</sup>)</td>
- <td style="width: 43px;">128.0.0.0</td>
- <td style="width: 146px;">191.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class C</td>
- <td style="width: 45px;">110</td>
- <td style="width: 175px;">2,097,152 (2<sup>21</sup>)</td>
- <td style="width: 160px;">256 (2<sup>8</sup>)</td>
- <td style="width: 29px;">536,870,912 (2<sup>29</sup>)</td>
- <td style="width: 43px;">192.0.0.0</td>
- <td style="width: 146px;">223.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class D (multicast)</td>
- <td style="width: 45px;">1110</td>
- <td style="width: 175px;">not defined</td>
- <td style="width: 160px;">not defined</td>
- <td style="width: 29px;">268,435,456 (2<sup>28</sup>)</td>
- <td style="width: 43px;">224.0.0.0</td>
- <td style="width: 146px;">239.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class E (reserved)</td>
- <td style="width: 45px;">1111</td>
- <td style="width: 175px;">not defined</td>
- <td style="width: 160px;">not defined</td>
- <td style="width: 29px;">268,435,456 (2<sup>28</sup>)</td>
- <td style="width: 43px;">240.0.0.0</td>
- <td style="width: 146px;">255.255.255.255</td>
- </tr>
- </tbody>
- </table>
- The simplest way to find the class of an address is to check the bits of its first octet. Once you find the the answer, you are required to output a character or a codepoint which represents one of the characters A, B, C, D or E.
- The given IP will always be valid, and ti will always be a string.- - IP will not have insignificant zeroes.
- - IP will not be in any form other than IPv4 dot notation.
- # Rules
- This is code-golf. Shortest answer in each language wins.
- # Task
- Given an IP address as a string, find its [IP address class.](https://www.guru99.com/ip-address-classes.html)
- For reference, here is a table:
- <table class="wikitable" style="width: 855px;">
- <tbody>
- <tr>
- <th style="width: 92px;">Class</th>
- <th style="width: 45px;">Leading<br>bits</th>
- <th style="width: 175px;">Number<br>of networks</th>
- <th style="width: 160px;">Addresses<br>per network</th>
- <th style="width: 29px;">Total addresses<br>in class</th>
- <th style="width: 43px;">Start address</th>
- <th style="width: 146px;">End address</th>
- </tr>
- <tr>
- <td style="width: 92px;">Class A</td>
- <td style="width: 45px;">0</td>
- <td style="width: 175px;">128 (2<sup>7</sup>)</td>
- <td style="width: 160px;">16,777,216 (2<sup>24</sup>)</td>
- <td style="width: 29px;">2,147,483,648 (2<sup>31</sup>)</td>
- <td style="width: 43px;">0.0.0.0</td>
- <td style="width: 146px;">127.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class B</td>
- <td style="width: 45px;">10</td>
- <td style="width: 175px;">16,384 (2<sup>14</sup>)</td>
- <td style="width: 160px;">65,536 (2<sup>16</sup>)</td>
- <td style="width: 29px;">1,073,741,824 (2<sup>30</sup>)</td>
- <td style="width: 43px;">128.0.0.0</td>
- <td style="width: 146px;">191.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class C</td>
- <td style="width: 45px;">110</td>
- <td style="width: 175px;">2,097,152 (2<sup>21</sup>)</td>
- <td style="width: 160px;">256 (2<sup>8</sup>)</td>
- <td style="width: 29px;">536,870,912 (2<sup>29</sup>)</td>
- <td style="width: 43px;">192.0.0.0</td>
- <td style="width: 146px;">223.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class D (multicast)</td>
- <td style="width: 45px;">1110</td>
- <td style="width: 175px;">not defined</td>
- <td style="width: 160px;">not defined</td>
- <td style="width: 29px;">268,435,456 (2<sup>28</sup>)</td>
- <td style="width: 43px;">224.0.0.0</td>
- <td style="width: 146px;">239.255.255.255</td>
- </tr>
- <tr>
- <td style="width: 92px;">Class E (reserved)</td>
- <td style="width: 45px;">1111</td>
- <td style="width: 175px;">not defined</td>
- <td style="width: 160px;">not defined</td>
- <td style="width: 29px;">268,435,456 (2<sup>28</sup>)</td>
- <td style="width: 43px;">240.0.0.0</td>
- <td style="width: 146px;">255.255.255.255</td>
- </tr>
- </tbody>
- </table>
- The simplest way to find the class of an address is to check the bits of its first octet. Once you find the the answer, you are required to output a character or a codepoint which represents one of the characters A, B, C, D or E.
- - The given IP will always be valid, and it will always be a string.
- - IP will not have insignificant zeroes.
- - IP will not be in any form other than IPv4 dot notation.
- # Rules
- This is code-golf. Shortest answer in each language wins.
#1: Initial revision
Find the IP address class
# Task Given an IP address as a string, find its [IP address class.](https://www.guru99.com/ip-address-classes.html) For reference, here is a table: <table class="wikitable" style="width: 855px;"> <tbody> <tr> <th style="width: 92px;">Class</th> <th style="width: 45px;">Leading<br>bits</th> <th style="width: 175px;">Number<br>of networks</th> <th style="width: 160px;">Addresses<br>per network</th> <th style="width: 29px;">Total addresses<br>in class</th> <th style="width: 43px;">Start address</th> <th style="width: 146px;">End address</th> </tr> <tr> <td style="width: 92px;">Class A</td> <td style="width: 45px;">0</td> <td style="width: 175px;">128 (2<sup>7</sup>)</td> <td style="width: 160px;">16,777,216 (2<sup>24</sup>)</td> <td style="width: 29px;">2,147,483,648 (2<sup>31</sup>)</td> <td style="width: 43px;">0.0.0.0</td> <td style="width: 146px;">127.255.255.255</td> </tr> <tr> <td style="width: 92px;">Class B</td> <td style="width: 45px;">10</td> <td style="width: 175px;">16,384 (2<sup>14</sup>)</td> <td style="width: 160px;">65,536 (2<sup>16</sup>)</td> <td style="width: 29px;">1,073,741,824 (2<sup>30</sup>)</td> <td style="width: 43px;">128.0.0.0</td> <td style="width: 146px;">191.255.255.255</td> </tr> <tr> <td style="width: 92px;">Class C</td> <td style="width: 45px;">110</td> <td style="width: 175px;">2,097,152 (2<sup>21</sup>)</td> <td style="width: 160px;">256 (2<sup>8</sup>)</td> <td style="width: 29px;">536,870,912 (2<sup>29</sup>)</td> <td style="width: 43px;">192.0.0.0</td> <td style="width: 146px;">223.255.255.255</td> </tr> <tr> <td style="width: 92px;">Class D (multicast)</td> <td style="width: 45px;">1110</td> <td style="width: 175px;">not defined</td> <td style="width: 160px;">not defined</td> <td style="width: 29px;">268,435,456 (2<sup>28</sup>)</td> <td style="width: 43px;">224.0.0.0</td> <td style="width: 146px;">239.255.255.255</td> </tr> <tr> <td style="width: 92px;">Class E (reserved)</td> <td style="width: 45px;">1111</td> <td style="width: 175px;">not defined</td> <td style="width: 160px;">not defined</td> <td style="width: 29px;">268,435,456 (2<sup>28</sup>)</td> <td style="width: 43px;">240.0.0.0</td> <td style="width: 146px;">255.255.255.255</td> </tr> </tbody> </table> The simplest way to find the class of an address is to check the bits of its first octet. Once you find the the answer, you are required to output a character or a codepoint which represents one of the characters A, B, C, D or E. - The given IP will always be valid, and ti will always be a string. - IP will not have insignificant zeroes. - IP will not be in any form other than IPv4 dot notation. # Rules This is code-golf. Shortest answer in each language wins.