IPv4 Network and Broadcast Addresses
Description:
You need to find the Network Address and Broadcast Address of an IPv4 address given in CIDR notation.
The format given is <IPv4 Address>/<CIDR>
An IPv4 address is a set of 4 bytes (octets) separated by periods. Each octet can only be the values 0-255
. Values padded with zeros up to 3 digits are acceptable (e.g 192.168.001.101
)
The number of CIDR
is the count of leading 1
bits in the 32-bit subnet mask. As IPv4 addresses are only 32 bits long, values less than 0
or greater than 32
are not permissible.
Example:
Input: 192.168.1.100/24
IP Address: 192.168.1.100
and Subnet Mask: 24 bits or 255.255.255.0
The subnet mask is a binary bitmask that denotes which bits in the IP address represent the network portion. The remaining bits are the host portion.
The network address is all-zeros in the host portion of the address. The broadcast address is all-ones in the host portion of the address.
192.168.1.100 11000000 10101000 00000001 01100100
255.255.255.0 11111111 11111111 11111111 00000000
|----------network---------|--host--|
192.168.1.0 11000000 10101000 00000001 00000000 <- network
192.168.1.255 11000000 10101000 00000001 11111111 <- broadcast
Your return value should be an array with two elements. The first element is a string containing the network address, and the second element is a string containing the broadcast address. If a bad IP address or CIDR value is given, return false
.
Similar Kata:
Stats:
Created | Jan 3, 2019 |
Published | Jan 3, 2019 |
Warriors Trained | 99 |
Total Skips | 25 |
Total Code Submissions | 180 |
Total Times Completed | 10 |
PHP Completions | 10 |
Total Stars | 3 |
% of votes with a positive feedback rating | 40% of 5 |
Total "Very Satisfied" Votes | 2 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 3 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |