How to use $sprintf - with field width and not padding

In reply to DVCoder:

Hi

For example - if my_number is 0x24 it prints ox24 (which is ok) but if my number is 0x8 - i want it to print 0x8 but keep the field width as 2 digits (which means that for example :

sprinft(“0x%X this is my number”, my_number)

i want to get for the 2 case :

0x24 this is my number
0x8(space) this is my number

as you can see i want to make the case in the second line that it will print 0x8 in 2 digits field width.

same question goes for the %d case…