Comments on Find the IP address class
Parent
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 | Leading bits |
Number of networks |
Addresses per network |
Total addresses in class |
Start address | End address |
---|---|---|---|---|---|---|
Class A | 0 | 128 (27) | 16,777,216 (224) | 2,147,483,648 (231) | 0.0.0.0 | 127.255.255.255 |
Class B | 10 | 16,384 (214) | 65,536 (216) | 1,073,741,824 (230) | 128.0.0.0 | 191.255.255.255 |
Class C | 110 | 2,097,152 (221) | 256 (28) | 536,870,912 (229) | 192.0.0.0 | 223.255.255.255 |
Class D (multicast) | 1110 | not defined | not defined | 268,435,456 (228) | 224.0.0.0 | 239.255.255.255 |
Class E (reserved) | 1111 | not defined | not defined | 268,435,456 (228) | 240.0.0.0 | 255.255.255.255 |
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.
JavaScript, 43 bytes …
3y ago
Japt, 26 25 20 bytes ;B …
26d ago
[Python 3], 56 bytes …
3y ago
Vyxal, 24 bytes ``` \.€hEb:L …
3y ago
[C (gcc)], 64 62 bytes Save …
3y ago
[C (gcc)], 55 bytes …
12d ago
Japt, 15 bytes Port of m90' …
2mo ago
J, 46 char ``` 'ABCDE'{:".{. …
2y ago
0 comment threads