Added code and output for B5.

This commit is contained in:
K 2024-10-09 20:14:30 +05:30
parent 906b58eb0a
commit 9dc91af758
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F
3 changed files with 37 additions and 0 deletions

35
Codes/Code-B5.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <iostream>
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
*/

Binary file not shown.

View File

@ -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) - [Output-A4](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-A4.pdf)
##### B5 - Subnetting and subnet mask ##### 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) - [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) - [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 ##### B6 - Link state & distance vector
- [Code-B6](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-B6.py) - [Code-B6](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-B6.py)