Convert Hex binary string to a value in Rules

How can I convert a binary hex string to a value.

I read the string form a CO2 sensor (T6613) device by the serial binding. I have added -Dfile.encoding=ISO-8859-1 in Java args so the read and write of 8bit characters to the /dev/ttyS0 work ok.

I have an item
String RS_CO2 “RS_CO2 [%s]” { serial="/dev/ttyS0@19200" }

In my rule I have

rule "CO2 rs2232 wait for device"
when 
     Item RS_CO2 changed
then
    
       var rsstring      = RS_CO2.state.toString    // The string looks like this "\u00FF\u00FA\u0002\u0002\u008A"	 . The last 2 bytes hold the value
       var check         = rsstring.substring(1,2)      // Reads byte FA to test the answer is right
       var valuestring = rsstring.substring(3,5)     // Reads the value string from the string

       if (check == "\u00FA")  //  right measure 
       {
          var value =  ????????????(valuestring)
          postUpdate(CO2, value)
       }

end

I have tried many conversions, but they all take a hexstring as a starting point, not a binary hex string.

Can anyone give me a hint on this issue and replace the ??? by a function. This can’t be to difficult?

Some methods here that may be useful

Hello Rossko57

Thank you for your help, but the answer is somewhere hidden in all the discussions. But you gave me a new insight with your answer and I now have it done. Far to complex and waiting for a simple solutions, but it is working.

rule "CO2 rs2232 wait for device"
    when 
         Item RS_CO2 changed
    then

           
           var rsstring    = RS_CO2.state.toString	
           var check          = rsstring.substring(1,2)    // check value
           var valuestring = rsstring.substring(3,4)    // high 
           var valuestring2 = rsstring.substring(4,5)   // low
           
           var char [] array = rsstring.toCharArray()
           val StringBuilder sb = new StringBuilder
           array.forEach (b | sb.append(Integer::toHexString(b) + " "))   // readable string for debug
     
           var char [] array2 = valuestring.toCharArray()
           val StringBuilder sb2 = new StringBuilder
           array2.forEach (b | sb2.append(Integer::toHexString(b)))  // high
     
           var char [] array3 = valuestring2.toCharArray()
           val StringBuilder sb3 = new StringBuilder
           array3.forEach (b | sb3.append(Integer::toHexString(b)))  // low
     
            
           if (check == "\u00fa")  // check right string
           {
              var value = Integer::parseInt(String::format("%s",sb2), 16)  //high
              var value2 = Integer::parseInt(String::format("%s",sb3), 16)  // low
              var value3 = value * 256 + value2
              
              postUpdate(AD_CO2, value3)
              logInfo("CO2 rs 232", "String CO2 =" + sb + "value =" + value3 )

           }

    end

And it works with this brute force solutions.