diff --git a/Codes/Code-B5.cpp b/Codes/Code-B5.cpp new file mode 100644 index 0000000..afc38cd --- /dev/null +++ b/Codes/Code-B5.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +void printSubnetMask(int prefixLength) { + int mask[4] = {0, 0, 0, 0}; + for (int i = 0; i < prefixLength; ++i) { + mask[i / 8] |= (1 << (7 - (i % 8))); + } + cout << "Subnet Mask for /" << prefixLength << ": "; + cout << mask[0] << "." << mask[1] << "." << mask[2] << "." << mask[3] << std::endl; +} + +int main() { + int prefixLength; + cout << "Enter the prefix length: "; + cin >> prefixLength; + + if (prefixLength >= 0 && prefixLength <= 32) { + printSubnetMask(prefixLength); + } + else { + cout << "Invalid prefix length!" << std::endl; + } + return 0; +} + +/* +OUTPUT: +Enter the prefix length: 22 +Subnet Mask for /22: 255.255.252.0 +Enter the prefix length: 0 +Subnet Mask for /0: 0.0.0.0 +Enter the prefix length: 32 +Subnet Mask for /32: 255.255.255.255 +*/ diff --git a/Printable outputs/Output-B5.pdf b/Printable outputs/Output-B5.pdf new file mode 100644 index 0000000..3c8c47a Binary files /dev/null and b/Printable outputs/Output-B5.pdf differ diff --git a/README.md b/README.md index 7a4f9aa..85860a2 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,10 @@ This Git repository is a comprehensive resource for the Computer Networks and Se - [Output-A4](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-A4.pdf) ##### B5 - Subnetting and subnet mask +- [Code-B5](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-B5.cpp) - [Handout-B5](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Handouts/Handout-B5.pdf) - [Write-up - B5](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Write-ups/Write-up%20-%20B5.pdf) +- [Output-B5](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-B5.pdf) ##### B6 - Link state & distance vector - [Code-B6](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-B6.py)