convert list of decimals to hexidecimals without getting truncated

Haakon Andor

I have a text file with a list of numbers that look like this

  1. 295147905179352825855
  2. 295147905179352825856
  3. 295147905179352825857
  4. 295147905179352825858

I'm trying to convert that list into hexidecimal numbers that look like this but all I get is 'truncated numbers. How do I convert that list to look like this?

  1. 00000000000000000000000000000000000000000000000fffffffffffffffff
  2. 0000000000000000000000000000000000000000000000100000000000000000
  3. 0000000000000000000000000000000000000000000000100000000000000001
  4. 0000000000000000000000000000000000000000000000100000000000000002

The output in terminal when converting is like "fcccccccca" and says "truncated over 20 digit" (I'm paraphrasing). I'm trying to get a 64 character hex.

Grismar

It looks like you're trying to convert large integers to hexadecimal strings, zero-padded to always show the full 256-bit hexadecimal representations:

n = 295147905179352825855

result = '{:0{}x}'.format(n, 64)
print(result)

Output:

00000000000000000000000000000000000000000000000fffffffffffffffff

Or if you prefer f-string notation:

result = f'{n:0{64}x}'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related