user48532: I'm working on an RFID system using a MFRC522 with this Library : https://github.com/miguelbalboa/rfid
Here's the code I have right now:
int A=(mfrc522.uid.uidByte[0]);
int B=(mfrc522.uid.uidByte[1]);
int C=(mfrc522.uid.uidByte[2]);
int D=(mfrc522.uid.uidByte[3]);

Serial.println("UID is %x %x %x %x", A, B, C, D);

This results in the following output:
UID is 35 C5 5A 59

My issue is - how do I first reverse that UID : from 35 C5 5A 59 to 59 5A C5 35 
- and second convert and print the corresponding decimal value of that reversed UID. In this case, it would be 1499120949.
I should mention that I need it as a string at the end to add it to the end of a POST command.

user7508: A standard way to convert individual bytes to a number is to use bit
shifts and bitwise OR, as shown in chrisl's answer. When doing this,
however, one has to take care not to overflow the bit shifts. On the
AVR-based Arduinos, an int is 16 bits long. Shifting it by
24 bit positions to the left is guaranteed to overflow, which in
C++ leads to undefined behavior.
The solution, as explained in Majenko's comment, is to cast to the final
type before shifting, like this:
uint32_t uid = (uint32_t) mfrc522.uid.uidByte[0] << 0
             | (uint32_t) mfrc522.uid.uidByte[1] << 8
             | (uint32_t) mfrc522.uid.uidByte[2] << 16
             | (uint32_t) mfrc522.uid.uidByte[3] << 24;

Note that I got rid of the useless intermediate variables A through
D.
Once you have have the numerical value, you may try to use it without
explicitly converting to a string. Instead, you rely on the print()
or println() methods to implicitly do the conversion only when needed,
as in
Serial.print("UID = ");
Serial.println(uid);

or even, on a network connection:
client.print(uid);

This will save you the memory needed to store the string. If you really
need to have the converted string in memory, which could happen if you
need to provide a Content-Length before sending the data, you can do so
with the function ultoa() from the avr-libc:
char uid_str[11];  // max = 10 digits + terminating NUL
ultoa(uid, uid_str, 10);  // convert to base 10

Please note that ltoa() is not appropriate here, as calling it
will implicitly convert the value to a signed long, which has the
potential to overflow and yield a negative result.
This “C string” – a NUL-terminated character array – can then
be converted to a String object if needed, but I advice you against doing so
if at all possible. String objects are more convenient to manipulate,
but they are absolutely not memory friendly, which can quickly become an
issue on most Arduinos.

48532: <p>I'm working on an RFID system using a MFRC522 with this Library : <a href="https://github.com/miguelbalboa/rfid" rel="nofollow noreferrer">https://github.com/miguelbalboa/rfid</a>
Here's the code I have right now:</p>

<pre><code>int A=(mfrc522.uid.uidByte[0]);
int B=(mfrc522.uid.uidByte[1]);
int C=(mfrc522.uid.uidByte[2]);
int D=(mfrc522.uid.uidByte[3]);

Serial.println("UID is %x %x %x %x", A, B, C, D);
</code></pre>

<p>This results in the following output:</p>

<pre><code>UID is 35 C5 5A 59
</code></pre>

<p>My issue is - how do I first reverse that UID : from <code>35 C5 5A 59 to 59 5A C5 35</code> 
- and second convert and print the corresponding decimal value of that reversed UID. In this case, it would be 1499120949.</p>

<p>I should mention that I need it as a string at the end to add it to the end of a POST command.</p>
 7508: <p>A standard way to convert individual bytes to a number is to use bit
shifts and bitwise OR, as shown in chrisl's answer. When doing this,
however, one has to take care not to overflow the bit shifts. On the
AVR-based Arduinos, an <code>int</code> is 16&nbsp;bits long. Shifting it by
24&nbsp;bit positions to the left is guaranteed to overflow, which in
C++ leads to undefined behavior.</p>

<p>The solution, as explained in Majenko's comment, is to cast to the final
type <em>before</em> shifting, like this:</p>

<pre><code>uint32_t uid = (uint32_t) mfrc522.uid.uidByte[0] &lt;&lt; 0
             | (uint32_t) mfrc522.uid.uidByte[1] &lt;&lt; 8
             | (uint32_t) mfrc522.uid.uidByte[2] &lt;&lt; 16
             | (uint32_t) mfrc522.uid.uidByte[3] &lt;&lt; 24;
</code></pre>

<p>Note that I got rid of the useless intermediate variables <code>A</code> through
<code>D</code>.</p>

<p>Once you have have the numerical value, you may try to use it without
explicitly converting to a string. Instead, you rely on the <code>print()</code>
or <code>println()</code> methods to implicitly do the conversion only when needed,
as in</p>

<pre><code>Serial.print("UID = ");
Serial.println(uid);
</code></pre>

<p>or even, on a network connection:</p>

<pre><code>client.print(uid);
</code></pre>

<p>This will save you the memory needed to store the string. If you really
need to have the converted string in memory, which could happen if you
need to provide a Content-Length before sending the data, you can do so
with the function <code>ultoa()</code> from the avr-libc:</p>

<pre><code>char uid_str[11];  // max = 10 digits + terminating NUL
ultoa(uid, uid_str, 10);  // convert to base 10
</code></pre>

<p>Please note that <code>ltoa()</code> is <strong>not</strong> appropriate here, as calling it
will implicitly convert the value to a <strong>signed</strong> <code>long</code>, which has the
potential to overflow and yield a negative result.</p>

<p>This “C string” –&nbsp;a NUL-terminated character array&nbsp;– can then
be converted to a String object if needed, but I advice you against doing so
if at all possible. String objects are more convenient to manipulate,
but they are absolutely not memory friendly, which can quickly become an
issue on most Arduinos.</p>
