Decorating Hex function to pad zeros

前端 未结 6 1879
无人共我
无人共我 2020-11-29 01:31

I wrote this simple function:

def padded_hex(i, l):
    given_int = i
    given_len = l

    hex_result = hex(given_int)[2:] # remove \'0x\' from beginning o         


        
6条回答
  •  一生所求
    2020-11-29 01:47

    If just for leading zeros, you can try zfill function.

    '0x' + hex(42)[2:].zfill(4) #'0x002a'
    

提交回复
热议问题