What you're asking doesn't make any sense. The integer 0011
and the integer 11
are exactly the same number.*
If you want to format them as strings to print them out or to search a text file, you can do that with, e.g., format(n, '04')
. It doesn't matter whether you're formatting 11
or 0011
, they're both the same number, and that number will format to the string '0011'
.
If you want to convert them to big-endian 32-bit C-style unsigned integers, again, they're both the same number, and struct.pack('>I', n)
will pack that number to the byte string b'\x00\x00\x00\x0b'
.
If you want to add them modulo 10000, again, they're both the same number, and (n + 9990) % 10000
will give you 1
.
No matter what operation you dream up, there will be no difference.
* Actually, in Python 2.x, number literals starting with 0
are treated as octal, not decimal, so 0011
is actually 9
, not 11
. And in 3.x numbers starting with 0
are a SyntaxError
, to avoid the confusion caused by accidentally writing octal numbers. But forget all that. We're not talking about the Python number literals, we're talking about something even simpler here: the numbers themselves.