-4

I need to create a function in python to generate a number in hex from 00:00:00 to FF:FF:FF the output can be a string but always formatted 6 char separated by ":" so it should look like this:

0 = 00:00:00
1 = 00:00:01
...
2816 = 00:0B:00
...
16777214 = FF:FF:EF
16777215 = FF:FF:FF
  • Often in programming (and in life) you need to break a problem into smaller pieces. "How do I convert an integer into its hex representation, separated by colons?" Well, first find out if you can convert it to its hex representation, _then_ add colons. Does this answer your question? [How to use hex() without 0x in Python?](https://stackoverflow.com/questions/16414559/how-to-use-hex-without-0x-in-python) Specifically, [eumiro's answer](https://stackoverflow.com/a/16414606/843953) shows you how to pad with zeros. Then adding colons is trivial. – Pranav Hosangadi Feb 22 '22 at 23:04

1 Answers1

0

Try this :

for dec_ldev in range(0,16777215):
    hex_ldev = hex(dec_ldev)[2:].zfill(6)
    print("{}{}{}:{}{}:{}{}".format('',*hex_ldev))