title: C++ to Java. Get result from byte array
body: <p>A have a program that written on C++. It receive byte array and convert it to value. I have some experience with C++ but after some days of research I realized that not enough.</p>
  <pre><code>quint32 id = getWORD(&amp;rawData[1]);
  </code></pre>
  <p>in my case <code>rawData = {0x03, 0xAD, 0x1D, 0xFA, 0x03, 0x02, 0x00, 0x00, 0x00, 0x3D, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6A, 0x00, 0x00}</code></p>
  <pre><code>uint32_t getWORD(const char* buf)
  {
      uint32_t val;
      memcpy(&amp;val, buf, sizeof(val));
      return val;
  }
  </code></pre>
  <p>If I understand correctly this method just convert this byte to uint32_t type</p>
  <p>And then, result is:</p>
  <pre><code>QString result = QString(&quot;%1&quot;).arg((quint32) id, 8, 16, QChar('0')).toUpper()
  </code></pre>
  <p>I have read about arg function <a href="https://doc.qt.io/qt-5/qstring.html" rel="nofollow noreferrer">here</a> but there are dozens of different constructors with different arguments, and I have never saw something similar in Java or Kotlin, so have no idea how to realize it.</p>
  <p>Will appreciate any hint</p>
  <p><strong>UPD:</strong></p>
  <pre><code>byte[] bytes = {(byte) 0xAD, (byte) 0x1D, (byte) 0xFA, (byte) 0x03};
  int result = ByteBuffer.wrap(bytes).getInt(); // = -1390544381
  </code></pre>
  <p>But negative value not looks like correct ID of device</p>
  <p>I have already think about <a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#format(java.lang.String,java.lang.Object...)" rel="nofollow noreferrer">String.format</a> but according to documentation of QString:</p>
  <blockquote>
  <p>QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar
  fillChar = QLatin1Char(' ')) const</p>
  <p>The base argument specifies the base to use when converting the
  integer a into a string. The base must be between 2 and 36.</p>
  <p>If fillChar is '0' (the number 0, ASCII 48), the locale's zero is
  used. For negative numbers, zero padding might appear before the minus
  sign.</p>
  </blockquote>
  <p>So I'm not sure that String.format can help in this case</p>