RapidMiner

How to convert hex to decimal values in RM Studio ?

SOLVED
Contributor

How to convert hex to decimal values in RM Studio ?

I have machine sensors data which I want to convert on the fly from hex to decimal so that I can use it further processing. Is there is a direct way or Reg Ex or function to do that in RM Studio ? I could see hex() and unhex() funcion in Radoop ( Generate Attributes) but not in Studio. Any help is appreciated.

 

Thanks

Reed

6 REPLIES

Re: How to convert hex to decimal values in RM Studio ?

Hello @reedevtaneja

 

There doesnot seem to be an operator to do that, however we can use the execute script operator to do this.and the script is very easy

Here is the script you will need and it is also in the attached example rmp process.

Please not that it changes all columns from hex to dec, so you will need to prefix it with  "select attributes" to pass only the desired ones.

Or depending on your use case, you cna hard code few things..

Hope this is helpful

 

 

ExampleSet exampleSet = operator.getInput(ExampleSet.class);

for (Attribute attribute : exampleSet.getAttributes()) {
    String name = attribute.getName();
    for (Example example : exampleSet) {
        //example[name] = example[name].toUpperCase();
		example[name] = Integer.parseInt(example[name].trim(), 16 );	
        
    }
}

return exampleSet;

Attachments

Contributor

Re: How to convert hex to decimal values in RM Studio ?

Thanks BP, It was quick and helpful. 

Re: How to convert hex to decimal values in RM Studio ?

For similar use casez: This is example of Binary to Integers

 

ExampleSet exampleSet = operator.getInput(ExampleSet.class);

for (Attribute attribute : exampleSet.getAttributes()) {
    String name = attribute.getName();
    for (Example example : exampleSet) {
        //example[name] = example[name].toUpperCase();
		example[name] = Integer.parseInt(example[name].trim(), 2 );	
        
    }
}

return exampleSet;

Re: How to convert hex to decimal values in RM Studio ?

This is example of Hex to Binary

 

 

ExampleSet exampleSet = operator.getInput(ExampleSet.class);

for (Attribute attribute : exampleSet.getAttributes()) {
    String name = attribute.getName();
    for (Example example : exampleSet) {
        //example[name] = example[name].toUpperCase();
		int myint = Integer.parseInt(example[name].trim(), 16 );	
		example[name] = Integer.toBinaryString(myint)
        
    }
}

return exampleSet;

Contributor

Re: How to convert hex to decimal values in RM Studio ?

Dear @

Attachments

Highlighted
Contributor

Re: How to convert hex to decimal values in RM Studio ?

[ Edited ]

Ran into the same problem... any help is highly appreciated. Thank you!

EDIT: solved it in my case, maybe the following change to the script is helpful for others:

 

ExampleSet exampleSet = operator.getInput(ExampleSet.class);

for (Attribute attribute : exampleSet.getAttributes()) {
    String name = attribute.getName();
    for (Example example : exampleSet) {
          //example[name] = example[name].toUpperCase();
		example[name] = new BigInteger(example[name].trim(), 16);
				 	 	
        
    }
}

return exampleSet;

You could also try Long type first (instead of int) if your hex values are not that big.

 

Best regards