@@ -557,7 +557,7 @@ public static boolean[] byteToBinary(final byte src, final int srcPos, final boo
557557 * @param srcPos the position in {@code src}, in bits, from where to start the conversion
558558 * @param dstInit the initial value for the result String
559559 * @param dstPos the position in {@code dst} where to copy the result
560- * @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
560+ * @param nHexs the number of chars to copy to {@code dst}, must be smaller or equal to the
561561 * width of the input (from srcPos to MSB)
562562 * @return {@code dst}
563563 * @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 8}
@@ -782,7 +782,7 @@ public static int hexDigitToInt(final char hexDigit) {
782782 * @param srcPos the position in {@code src}, in char unit, from where to start the conversion.
783783 * @param dstInit initial value of the destination byte.
784784 * @param dstPos the position of the LSB, in bits, in the result byte.
785- * @param nHex the number of Chars to convert.
785+ * @param nHex the number of chars to convert.
786786 * @return a byte containing the selected bits.
787787 * @throws IllegalArgumentException Thrown on invalid input like {@code (nHex - 1) * 4 + dstPos >= 8}.
788788 */
@@ -815,7 +815,7 @@ public static byte hexToByte(final String src, final int srcPos, final byte dstI
815815 * conversion
816816 * @param dstInit initial value of the destination int
817817 * @param dstPos the position of the LSB, in bits, in the result int
818- * @param nHex the number of Chars to convert
818+ * @param nHex the number of chars to convert
819819 * @return an int containing the selected bits
820820 * @throws IllegalArgumentException Thrown on invalid input like {@code (nHex - 1) * 4 + dstPos >= 32}
821821 */
@@ -826,8 +826,9 @@ public static int hexToInt(final String src, final int srcPos, final int dstInit
826826 if ((nHex - 1 ) * 4 + dstPos >= 32 ) {
827827 throw new IllegalArgumentException ("(nHex - 1) * 4 + dstPos is greater or equal to than 32" );
828828 }
829- if (srcPos + nHex > src .length ()) {
830- throw new IllegalArgumentException (String .format ("srcPos %,d, + nHex %,d > src.length()" , srcPos , nHex , src .length ()));
829+ if (srcPos < 0 || nHex < 0 || srcPos > src .length () - nHex ) {
830+ throw new IllegalArgumentException (
831+ String .format ("srcPos %,d, dstInit %,d, dstPos %,d, nHex %,d, src.length() %,d" , srcPos , dstInit , dstPos , nHex , src .length ()));
831832 }
832833 int out = dstInit ;
833834 for (int i = 0 ; i < nHex ; i ++) {
@@ -848,20 +849,20 @@ public static int hexToInt(final String src, final int srcPos, final int dstInit
848849 * conversion
849850 * @param dstInit initial value of the destination long
850851 * @param dstPos the position of the LSB, in bits, in the result long
851- * @param nHex the number of Chars to convert
852+ * @param nHex the number of chars to convert
852853 * @return a long containing the selected bits
853854 * @throws IllegalArgumentException Thrown on invalid input like {@code (nHex - 1) * 4 + dstPos >= 64}
854855 */
855- public static long hexToLong (final String src , final int srcPos , final long dstInit , final int dstPos ,
856- final int nHex ) {
856+ public static long hexToLong (final String src , final int srcPos , final long dstInit , final int dstPos , final int nHex ) {
857857 if (0 == nHex ) {
858858 return dstInit ;
859859 }
860860 if ((nHex - 1 ) * 4 + dstPos >= 64 ) {
861861 throw new IllegalArgumentException ("(nHex - 1) * 4 + dstPos is greater or equal to than 64" );
862862 }
863- if (srcPos + nHex > src .length ()) {
864- throw new IllegalArgumentException (String .format ("srcPos %,d, + nHex %,d > src.length()" , srcPos , nHex , src .length ()));
863+ if (srcPos < 0 || nHex < 0 || srcPos > src .length () - nHex ) {
864+ throw new IllegalArgumentException (
865+ String .format ("srcPos %,d, dstInit %,d, dstPos %,d, nHex %,d, src.length() %,d" , srcPos , dstInit , dstPos , nHex , src .length ()));
865866 }
866867 long out = dstInit ;
867868 for (int i = 0 ; i < nHex ; i ++) {
@@ -882,20 +883,20 @@ public static long hexToLong(final String src, final int srcPos, final long dstI
882883 * conversion
883884 * @param dstInit initial value of the destination short
884885 * @param dstPos the position of the LSB, in bits, in the result short
885- * @param nHex the number of Chars to convert
886+ * @param nHex the number of chars to convert
886887 * @return a short containing the selected bits
887888 * @throws IllegalArgumentException Thrown on invalid input like {@code (nHex - 1) * 4 + dstPos >= 16}
888889 */
889- public static short hexToShort (final String src , final int srcPos , final short dstInit , final int dstPos ,
890- final int nHex ) {
890+ public static short hexToShort (final String src , final int srcPos , final short dstInit , final int dstPos , final int nHex ) {
891891 if (0 == nHex ) {
892892 return dstInit ;
893893 }
894894 if ((nHex - 1 ) * 4 + dstPos >= 16 ) {
895895 throw new IllegalArgumentException ("(nHex - 1) * 4 + dstPos is greater or equal to than 16" );
896896 }
897- if (srcPos + nHex > src .length ()) {
898- throw new IllegalArgumentException (String .format ("srcPos %,d, + nHex %,d > src.length()" , srcPos , nHex , src .length ()));
897+ if (srcPos < 0 || nHex < 0 || srcPos > src .length () - nHex ) {
898+ throw new IllegalArgumentException (
899+ String .format ("srcPos %,d, dstInit %,d, dstPos %,d, nHex %,d, src.length() %,d" , srcPos , dstInit , dstPos , nHex , src .length ()));
899900 }
900901 short out = dstInit ;
901902 for (int i = 0 ; i < nHex ; i ++) {
@@ -1008,7 +1009,7 @@ public static byte[] intToByteArray(final int src, final int srcPos, final byte[
10081009 * @param srcPos the position in {@code src}, in bits, from where to start the conversion
10091010 * @param dstInit the initial value for the result String
10101011 * @param dstPos the position in {@code dst} where to copy the result
1011- * @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
1012+ * @param nHexs the number of chars to copy to {@code dst}, must be smaller or equal to the
10121013 * width of the input (from srcPos to MSB)
10131014 * @return {@code dst}
10141015 * @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 32}
@@ -1216,7 +1217,7 @@ public static byte[] longToByteArray(final long src, final int srcPos, final byt
12161217 * @param srcPos the position in {@code src}, in bits, from where to start the conversion
12171218 * @param dstInit the initial value for the result String
12181219 * @param dstPos the position in {@code dst} where to copy the result
1219- * @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
1220+ * @param nHexs the number of chars to copy to {@code dst}, must be smaller or equal to the
12201221 * width of the input (from srcPos to MSB)
12211222 * @return {@code dst}
12221223 * @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 64}
@@ -1440,7 +1441,7 @@ public static byte[] shortToByteArray(final short src, final int srcPos, final b
14401441 * @param srcPos the position in {@code src}, in bits, from where to start the conversion
14411442 * @param dstInit the initial value for the result String
14421443 * @param dstPos the position in {@code dst} where to copy the result
1443- * @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
1444+ * @param nHexs the number of chars to copy to {@code dst}, must be smaller or equal to the
14441445 * width of the input (from srcPos to MSB)
14451446 * @return {@code dst}
14461447 * @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 16}
0 commit comments