Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

77%
+5 −0
Challenges Find the IP address class

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...

7 answers  ·  posted 3y ago by Razetime‭  ·  last activity 27d ago by Shaggy‭

Question code-golf
#2: Post edited by user avatar celtschk‭ · 2021-12-16T03:50:44Z (almost 3 years ago)
Fixed a typo
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 by user avatar Razetime‭ · 2021-12-07T12:44:56Z (almost 3 years ago)
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.