Both the methods mentioned will work.
The generic way to do it is to consider the long as four bytes, end to end. Call them AABBCCDD. You can only send one byte at a time because the UART is only 8 bits wide so you need to extract each of the four 8-bit parts individually.
Using AABBCCDD as the example:
The least significant 8 bits can be isolated by ANDing the long with 0xFF, AABBCCDD & 0xFF = 0xDD.
The next most significant bits can be isolated with AABBCCDD & 0x0000FF00 then shifted so CC is in the lowest bits with >> 8.
The next most significant bits can be isolated with AABBCCDD & 0x00FF0000 then shifted so BB is in the lowest bits with >> 16.
The most sgnificant bits can be isolated with AABBCCDD & 0xFF00000000 then shifted so AA is in the lowest bits with >> 24.
If the data has to be sent most significant bits first, simply reverse the order of the four instructions.
You can also do it with a union where you declare one long and four bytes. Writing to the long will make each byte hold bits 31:24, 23:16, 15:8, 7:0 which you can then pass to the UART as 8-bit values.
I presume that OP did not mean long as a numeric type, but as a string type. Assuming it is the case, once the number has a variable size should control array indexing by reaching the null terminator character.
Just reverse the processes listed above to send the value as 4 binary 'bytes'.
However you need to be aware that the simple approach you outline above is subject to synchronisation issues: if it sees 'noise' and interprets that as a valid value then all of the subsequent values will be put into the wrong 'byte' of the resulting value; similarly, if you miss a value then you will probably be waiting for a while to receive the 4th 'byte'.
Susan
...to synchronize you
* either need a defined time of no transmission between sending a complete variable. At the receiver side you need a timeout to reset (synchronize) your receiving routine.
* or you need to transfer a known sync pattern. Best is to use a combination that is not valid ( or at least : not likely) with the variable to transfer. With long variables all combinations are valid (in opposite to float variables).