Skip to content

Instantly share code, notes, and snippets.

@Wqrld
Created March 6, 2023 09:32
Show Gist options
  • Save Wqrld/e76e6da63b649cd57911eb62bddd5da7 to your computer and use it in GitHub Desktop.
Save Wqrld/e76e6da63b649cd57911eb62bddd5da7 to your computer and use it in GitHub Desktop.
Subnet masks in java
public class Main {
public static void main(String[] args) {
int binary = 0x00;
for (int i = 0; i <= 32; i++) {
System.out.printf("%d.%d.%d.%d (/%d)%n", (binary >> 24) & 0xFF, (binary >> 16) & 0xFF, (binary >> 8) & 0xFF, binary & 0xFF, i);
binary >>= 1;
binary |= (1 << 31);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment