Question

I am developing an app to send Infrared Codes in the form of int[]. I have a String of hex code: "0000 0048 0000 0018 00c1 00c0 0031 0090 0031 0090 0031 0030 0031 0090 0031 0090 0031 0090 0031 0090 0031 0090 0031 0030 0031 0030 0031 0030 0031 0030 0031 0030 0031 0090 0031 0030 0031 0030 0031 0030 0031 0030 0031 0030 0031 0090 0031 0090 0031 0090 0031 073b" and I need to convert it to an int[] split at the spaces in decimal form.

String hexCode = "0000 0048 0000 0018 00c1 00c0 0031 0090 0031 0090 0031 0030 0031 0090 0031 0090 0031 0090 0031 0090 0031 0090 0031 0030 0031 0030 0031 0030 0031 0030 0031 0030 0031 0090 0031 0030 0031 0030 0031 0030 0031 0030 0031 0030 0031 0090 0031 0090 0031 0090 0031 073b"
String decimalCode = hex2dec(hexCode); //I don't know how to convert this and keep the spaces
String[] decArray = decimalCode.split(" ");
int[] final = decArray; //Not sure how to do this. Maybe a for loop?

I have been working at this for a few hours and am getting frustrated. I can't convert from hex to decimal string successfully and then I can't put it into an int[].

Please help!

No correct solution

OTHER TIPS

i'm not sure what you're aiming at, but you had the right idea so far... but instead of doing a hex2dec and then split you should reverse the order, say: first split then convert....

String hexCode = "0000 0048 0000 0018 00c1 00c0 0031 0090 0031 0090 0031 0030 0031 0090 0031 0090 0031 0090 0031 0090 0031 0090 0031 0030 0031 0030 0031 0030 0031 0030 0031 0030 0031 0090 0031 0030 0031 0030 0031 0030 0031 0030 0031 0030 0031 0090 0031 0090 0031 0090 0031 073b"

//splitting the hexcode into a string array
String[] splits =  decimalCode.split(" ");

//getting the length of the string aray, we need this to set
//the right size of the int[]
int amount = splits.length();

//values are the values wich you're interested in...
//we create the array with proper size(amount)
int[] values = new int[amount]

//now we iterate through the strong[] splits
for (int i = 0; i < amount; i ++){

    //we take a string vrom the array
    String str = splits[i];

    //the we parse the stringv into a int-value
    int parsedValue = Integer.parseInt(str, 16);

     //and fill up the value-array
    values[i] = parsedValue;
}
//when we're through with the iteration loop, we're done (so far)

as mentioned above, i'm not so sure what you're aiming at... this may result in a wrong parsing method...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top