To do this in C:
sprintf(buffer, "%08d", n);
which convert integer
n to a 8-character string padded with leading 0s.
In bash, you can also use printf
For the previous example:
str=$(printf "%08d" $n)
where $n is the integer and $str contains the converted string.