Решил найти адрес сети по принципу, как в свое время решал такое-же 12 задание в ЕГЭ по информатике, но почему-то вылетает ArrayIndexOutOfBoundsException
package com.javarush.task.task21.task2101;
/*
Определяем адрес сети
*/
public class Solution {
public static void main(String[] args) {
byte[] ip = new byte[]{(byte) 192, (byte) 168, 1, 2};
byte[] mask = new byte[]{(byte) 255, (byte) 255, (byte) 254, 0};
byte[] netAddress = getNetAddress(ip, mask); //ArrayIndexOutOfBoundsException
print(ip); //11000000 10101000 00000001 00000010
print(mask); //11111111 11111111 11111110 00000000
print(netAddress); //11000000 10101000 00000000 00000000
}
public static byte[] getNetAddress(byte[] ip, byte[] mask) {
return new byte[]{ ip[1], ip[2], (byte) (ip[3] & mask[3]), mask[4]};
}
public static void print(byte[] bytes) {
}
}