title: Multiple data conversion with groovy
body: <p>I have a problem doing several conversions on some data.
  I get a response from a request that contains base64 encoded bytes and I'd like to get them in hexa.</p>
  
  <p>This is a String type:</p>
  
  <pre><code>log.info "type data base 64 : " + dataBase64.getClass().getName()
  INFO:type data base 64 : java.lang.String
  </code></pre>
  
  <p>Then I decode it:</p>
  
  <pre><code>data = dataBase64.decodeBase64() 
  log.info "type data : " + data.getClass().getName()
  
  INFO:type data : [B  =&gt; ?? there is something strange here
  
  log.info "data = " + data
  INFO:data = [0, 33, 0, 0, -74, 0, 16, 0, 0, 1, 0, 10, 3, 0, 0, 0, 28, 120, -45, 28, 90, 95, 25, -14, -119, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  </code></pre>
  
  <p>I want this data in bytes in order to recover an address in bytes 22 to 24
  If I do </p>
  
  <pre><code>log.info "dataHex = "  + data.encodeHex()
  INFO:dataHex = 00210000b60010000001000a030000001c78d31c5a5f19f289ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01000000000000000000000000000000000000000000000000000000000000000000000000000000
  </code></pre>
  
  <p>I want to recover the <code>19f289</code> part. The problem is that I cannot convert data[22] to data[24]
  <code>data[22].encodeHex</code> fails (the data[22] type is Byte, not Byte[])</p>
  
  <p>If I try to use toHexString on each byte required, I encounter a problem when handling negative values</p>
  
  <pre><code>for (i=22;i&lt;25;i++)
  {
      myInt = data[i]
      log.info Integer.toHexString(myInt) 
  }
  </code></pre>
  
  <p>gives </p>
  
  <pre><code>INFO:19
  INFO:fffffff2
  INFO:ffffff89
  </code></pre>
  
  <p>Is there any clean way to do this ? 
  I could try to extract the substring from dataHex after conversion to String (I haven't tried it yet) but I don't understand why I can convert simply a byte to hexadecimal</p>
  
  <p>if anyone knows ... </p>