0

I'm working on a cryptography project and I need to generate all hexadecimal possible numbers (length of the number= 16 bits in binary) and put them in a list in order to use them later.

Any suggestions?

Thanks in advance

2 Answers 2

1

(Yet) another Python one liner :

a = [hex(x) for x in xrange(0,pow(2, 16))]

EDIT : Given all the comments, we now have :

a = map(hex, xrange(pow(2,16) - 1))
Sign up to request clarification or add additional context in comments.

4 Comments

Shouldn't it not have the -1 at the end since xrange generates up to upperlimit-1?
You might want to add in map for completeness. a = map(hex,xrange(pow(2,16)))
the 0 in xrange should also be superfluous (xrange should start at 0)
you can also use the struct or binascii libraries to translate.
1

Why not generate all the integers from 0 to 2^16-1, and convert to hex? Yes, I know that it could be done more efficiently, but you are doing this ONCE. Why make things difficult?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.