@Test public void testConvertToFourBytes() throws Exception { result2 = IsisUtil.convertToFourBytes(250); assertThat(result2.length, is(4)); }
public static byte[] convertToFourBytes(int numberToConvert) { byte[] numInBytes = new byte[4]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = 0; numInBytes[3] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; numInBytes[3] = hexas[1]; } else if (hexas.length == 3) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; numInBytes[3] = hexas[2]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; numInBytes[3] = hexas[3]; } return numInBytes; }
IsisUtil { public static byte[] convertToFourBytes(int numberToConvert) { byte[] numInBytes = new byte[4]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = 0; numInBytes[3] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; numInBytes[3] = hexas[1]; } else if (hexas.length == 3) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; numInBytes[3] = hexas[2]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; numInBytes[3] = hexas[3]; } return numInBytes; } }
IsisUtil { public static byte[] convertToFourBytes(int numberToConvert) { byte[] numInBytes = new byte[4]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = 0; numInBytes[3] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; numInBytes[3] = hexas[1]; } else if (hexas.length == 3) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; numInBytes[3] = hexas[2]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; numInBytes[3] = hexas[3]; } return numInBytes; } private  IsisUtil(); }
IsisUtil { public static byte[] convertToFourBytes(int numberToConvert) { byte[] numInBytes = new byte[4]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = 0; numInBytes[3] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; numInBytes[3] = hexas[1]; } else if (hexas.length == 3) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; numInBytes[3] = hexas[2]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; numInBytes[3] = hexas[3]; } return numInBytes; } private  IsisUtil(); static boolean sameNetwork(Ip4Address ip1, Ip4Address ip2, byte[] mask); static String systemId(byte[] bytes); static String systemIdPlus(byte[] bytes); static String areaAddres(byte[] bytes); static List<Byte> areaAddressToBytes(String address); static int getPduHeaderLength(int pduType); static byte[] addLengthAndMarkItInReserved(byte[] isisPacket, int lengthBytePos1,
                                                      int lengthBytePos2, int reservedBytePos); static byte[] addChecksum(byte[] isisPacket, int checksumBytePos1, int checksumBytePos2); static byte[] framePacket(byte[] isisPacket, int interfaceIndex); static List<Byte> sourceAndLanIdToBytes(String id); static byte[] getPaddingTlvs(int currentLength); static byte[] convertToTwoBytes(int numberToConvert); static byte[] convertToFourBytes(int numberToConvert); static byte[] getP2pHelloPdu(IsisInterface isisInterface, boolean paddingEnabled); static byte[] getL1HelloPdu(IsisInterface isisInterface, boolean paddingEnabled); static byte[] getL2HelloPdu(IsisInterface isisInterface, boolean paddingEnabled); static int byteToInteger(byte[] bytesToConvert); static long byteToLong(byte[] bytesToConvert); static byte[] convertToFourBytes(long numberToConvert); static String toEightBitBinary(String binaryString); static String toFourBitBinary(String binaryString); static byte[] convertToThreeBytes(int numberToConvert); static String prefixConversion(byte[] bytes); static byte[] prefixToBytes(String prefix); static boolean checkIsDis(String systemId); static String removeTailingZeros(String systemId); }
IsisUtil { public static byte[] convertToFourBytes(int numberToConvert) { byte[] numInBytes = new byte[4]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = 0; numInBytes[3] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; numInBytes[3] = hexas[1]; } else if (hexas.length == 3) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; numInBytes[3] = hexas[2]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; numInBytes[3] = hexas[3]; } return numInBytes; } private  IsisUtil(); static boolean sameNetwork(Ip4Address ip1, Ip4Address ip2, byte[] mask); static String systemId(byte[] bytes); static String systemIdPlus(byte[] bytes); static String areaAddres(byte[] bytes); static List<Byte> areaAddressToBytes(String address); static int getPduHeaderLength(int pduType); static byte[] addLengthAndMarkItInReserved(byte[] isisPacket, int lengthBytePos1,
                                                      int lengthBytePos2, int reservedBytePos); static byte[] addChecksum(byte[] isisPacket, int checksumBytePos1, int checksumBytePos2); static byte[] framePacket(byte[] isisPacket, int interfaceIndex); static List<Byte> sourceAndLanIdToBytes(String id); static byte[] getPaddingTlvs(int currentLength); static byte[] convertToTwoBytes(int numberToConvert); static byte[] convertToFourBytes(int numberToConvert); static byte[] getP2pHelloPdu(IsisInterface isisInterface, boolean paddingEnabled); static byte[] getL1HelloPdu(IsisInterface isisInterface, boolean paddingEnabled); static byte[] getL2HelloPdu(IsisInterface isisInterface, boolean paddingEnabled); static int byteToInteger(byte[] bytesToConvert); static long byteToLong(byte[] bytesToConvert); static byte[] convertToFourBytes(long numberToConvert); static String toEightBitBinary(String binaryString); static String toFourBitBinary(String binaryString); static byte[] convertToThreeBytes(int numberToConvert); static String prefixConversion(byte[] bytes); static byte[] prefixToBytes(String prefix); static boolean checkIsDis(String systemId); static String removeTailingZeros(String systemId); static final int ETHER_HEADER_LEN; static final int ID_SIX_BYTES; static final int ID_PLUS_ONE_BYTE; static final int ID_PLUS_TWO_BYTE; static final int THREE_BYTES; static final int TWO_BYTES; static final int SIX_BYTES; static final int EIGHT_BYTES; static final int FOUR_BYTES; static final int PADDING_FIXED_LENGTH; static final int TLVHEADERLENGTH; static final int INITIAL_BANDWIDTH; }