I need to convert an int to a byte array in Micro Framework so it can be streamed to serial. This is happening in a time-sensitive area of the code where a delay caused by the garbage collector could take too long.
Normally I’d cast the int to string and thence to a char array. But that creates a heap object that risks garbage collection.
Is there an efficient way to do this? I can do it in a loop that uses modulo 10 arithmetic but that would be slow. In C I've used sprintf to convert to a pre-allocated array, which would be fine.