How to get the sum of a string in hexadecimal

0

For example I have this string:

String inpu = "0E00005031544D50434B2E733139"

and I need to do the sum of two in two like this: 0E+00+00+50 and so on

private static String getSum(String input) {
    int sum = 0;
    int x=0;
    int y=2;
    for (int i = 0; i <= input.length(); i++) {
        System.out.println("x:"+x);
        System.out.println("y:"+y);
        System.out.println("1:"+sum);
        sum +=Integer.parseInt(input.substring(x, y), 16);
        System.out.println("2:"+sum);
        x+=2;
        y+=2;
        if(y==input.length()){
            i=input.length();
        }
        System.out.println("x1:"+x);
        System.out.println("y1:"+y);
    }
    String hex = Integer.toHexString(sum);
    //String hex = String.valueOf(sum);
    return hex.toUpperCase();
}
    
asked by Jose Rodolfo De Loza Esquivias 21.10.2018 в 04:28
source

0 answers