Ask Your Question

# How to make a hexadecimal number into a string

I generate a hexadecimal number 0xffffffffffffffffffffffffffffffff like

s=0

for i in range(128):

s=s+2^i

s=hex(s)

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

from sage.crypto.mq.rijndael_gf import RijndaelGF

rgf = RijndaelGF(4, 4)

state = rgf._hex_to_GF('ffffffffffffffffffffffffffffffff')

edit retag close merge delete

## 1 Answer

Sort by » oldest newest most voted

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

sage: s=123456
sage: s.hex()
'1e240'


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

sage: hex(s)
'0x1e240'


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

sage: hex(s)[2:]
'1e240'

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 37 times

Last updated: May 21