Cześć,
Napisałem mini program do tworzenia adresów, masek itp. Dlaczego nic mi się nie wyświetla?
public class Main {
public static void main(String[] args) {
byte[] ipNumber = new byte[]{(byte) 192, (byte) 168, 1, 2};
byte[] netMask = new byte[]{(byte) 255, (byte) 255, (byte) 254, 0};
byte[] netAddress = getNetAddress(ipNumber, netMask);
print(ipNumber);
print(netMask);
print(netAddress);
}
public static byte[] getNetAddress(byte[] ip, byte[] mask) {
byte[] netAddress = new byte[4];
for (int i = 0; i < netAddress.length; i++)
netAddress[i] = (byte) (ip[i] & mask[i]);
return netAddress;
}
public static void print(byte[] bytes) {
String binary;
for (byte aByte : bytes) {
binary = Integer.toBinaryString(256 + (int) aByte);
System.out.print(binary.substring(binary.length()));
}
}
}
Potrzebuje efektu świeżego oka, ewentualnie snu :)