So, I am learning Python. To help my understanding, I was wondering how someone might make this code more efficient.
Purpose:
Take a 32-bit value (tempCode) and output each nibble. My way was to use a string, basically shifting out the binary value from bit 0 to bit 31 into the string.
i = 1
binString = ''
regSize = 32
while (i <= regSize):
binString = str(tempCode & 1) + binString
tempCode >>= 1
if ( (i%4) == 0 ): binString = ' ' + binString
i += 1
print "In binary: ", binString, "\n"
Output would be:
You entered: 0xF0A
In binary: 0000 0000 0000 0000 0000 1111 0000 1010