title: Decoding a hex string
body: <p>This is part of a bigger problem where we needed to port an old application to a new device (and of course to another programming language/framework). After a lot of effort ( sniffing the comm lines, reverse engineering the transmitted data for about a 2-3 weeks ) I managed to narrow in on what I think are the 4 bytes that contains 2 numbers. One of the number is a temperature reading like 30.51, 30.46 etc as shown in the first column (of Table 01). The other value is a float that can be in the range of something like 3.9 to 3.6 ( and even lower, with 4 decimals ). The 4 hex bytes (col 2 of Table 01) should contain both these values. I had to do some reverse engineering because no documentation is available nor the source code. I managed to narrow in on the part of java code that I think decodes the hex strings into 2 number as stated. Will someone be able to check if the code is what I think that it is? I am not a java programmer and I mostly deal with other programming languages. So I will need couple of things</p>
  
  <ol>
  <li>Is the attached code responsible for decoding the hex into the 3 float numbers? This is the most important</li>
  <li>If possible refactor a bit of that code so that it can run on (<a href="https://www.compilejava.net/" rel="nofollow noreferrer">https://www.compilejava.net/</a>). This is so that I can try test the algo with different sets of hex numbers.</li>
  <li>"If possible" add some comments</li>
  </ol>
  
  <p>Table 01</p>
  
  <pre><code>30.51 =&gt; 01:53:4e:98
  30.46 =&gt; 01:53:8e:94
  30.43 =&gt; 01:53:8e:91
  30.39 =&gt; 01:53:8e:8e
  30.39 =&gt; 01:53:4e:8e
  
  12.36 =&gt; 01:52:88:b1
  16.01 =&gt; 01:52:c9:cf
  18.65 =&gt; 01:52:ca:a5
  21.14 =&gt; 01:52:8b:74
  </code></pre>
  
  <p>If there is any information needed please let me know because I have spent a lot of time trying to figure this out. I can record more numbers if needed.</p>
  
  <p>Btw the number on the left is a temperature reading ( in celsius ). So that "may" involve a multiplication in the end to arrive at the number? I am not so sure about that but I thought I'd mention what I know about this.</p>
  
  <p>I don't have the time to learn java to fix this ( it is super rare for us to deal with java ) and I have already spent close to a month on this. Really appreciate any help to just clear this hurdle. Here is the java code that decodes the hex to 2 numbers. I got this by reverse engineering the legacy app. Please note that I deleted the decompiled code that I posted earlier because I was just made aware of the fact that it is covered under an NDA.</p>
  
  <p>Oops, I made a mistake of not mentioning that finally this needed to be plugged into a Python program - as I was mentioning it was part of a much bigger Python project, nearly all of which I've coded and works great. And a huge apology for not mentioning that (and forgetting to add the Python tag). I will have to rewrite this in Python.</p>