Ask Your Question

How to make a hexadecimal number into a string

asked 2021-05-21 22:49:13 +0100

Sanu gravatar image

I generate a hexadecimal number 0xffffffffffffffffffffffffffffffff like


for i in range(128):



I want to make it string like 'ffffffffffffffffffffffffffffffff' so that I can pass it as follows:

from import RijndaelGF

rgf = RijndaelGF(4, 4)

state = rgf._hex_to_GF('ffffffffffffffffffffffffffffffff')

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2021-05-21 23:20:59 +0100

Glenn Tesler gravatar image

For a Sage integer (vs. python int), s.hex() gives just the hex digits, without the prefix '0x':

sage: s=123456                                                                  
sage: s.hex()                                                                   

hex(s) includes the prefix '0x':

sage: hex(s)                                                                    

You could strip off '0x' with hex(s)[2:], but s.hex() is simpler.

sage: hex(s)[2:]                                                                
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-05-21 22:49:13 +0100

Seen: 830 times

Last updated: May 21 '21