0

I use Python 3.4. I want to generate a list that contains integers, relating to the corresponding hex by the algorithm:

hex-view:

000000 // first value in list
010101 // second
020202 // third

.....
FFFFFF // end.

After, I just use int:

[int(x) for x in hex_list].

How to generate a hex list? Many thanks.

0

4 Answers 4

3

Too much work.

[x * 0x010101 for x in range(256)]
Sign up to request clarification or add additional context in comments.

2 Comments

@AhsanulHaque: Why, when the asker is just going to turn around and call int()?
Oh, sorry, didn't see that. Okay then. I assumed the end result will be list of hex.
3

To generate the initial hex list:

l = ['0x'+format(i, '06x') for i in range(0, 16777216, 65793)]

To convert it to int:

i = list(map(lambda x:int(x,0), l))

Thus l looks like:

['0x000000', '0x010101', '0x020202', '0x030303', '0x040404', '0x050505', '0x060606', '0x070707', '0x080808', '0x090909', '0x0a0a0a', '0x0b0b0b', '0x0c0c0c', '0x0d0d0d', '0x0e0e0e', '0x0f0f0f', '0x101010', '0x111111', '0x121212', '0x131313', '0x141414', '0x151515', '0x161616', '0x171717', '0x181818', '0x191919', '0x1a1a1a', '0x1b1b1b', '0x1c1c1c', '0x1d1d1d', '0x1e1e1e', '0x1f1f1f', '0x202020', '0x212121', '0x222222', '0x232323', '0x242424', '0x252525', '0x262626', '0x272727', '0x282828', '0x292929', '0x2a2a2a', '0x2b2b2b', '0x2c2c2c', '0x2d2d2d', '0x2e2e2e', '0x2f2f2f', '0x303030', '0x313131', '0x323232', '0x333333', '0x343434', '0x353535', '0x363636', '0x373737', '0x383838', '0x393939', '0x3a3a3a', '0x3b3b3b', '0x3c3c3c', '0x3d3d3d', '0x3e3e3e', '0x3f3f3f', '0x404040', '0x414141', '0x424242', '0x434343', '0x444444', '0x454545', '0x464646', '0x474747', '0x484848', '0x494949', '0x4a4a4a', '0x4b4b4b', '0x4c4c4c', '0x4d4d4d', '0x4e4e4e', '0x4f4f4f', '0x505050', '0x515151', '0x525252', '0x535353', '0x545454', '0x555555', '0x565656', '0x575757', '0x585858', '0x595959', '0x5a5a5a', '0x5b5b5b', '0x5c5c5c', '0x5d5d5d', '0x5e5e5e', '0x5f5f5f', '0x606060', '0x616161', '0x626262', '0x636363', '0x646464', '0x656565', '0x666666', '0x676767', '0x686868', '0x696969', '0x6a6a6a', '0x6b6b6b', '0x6c6c6c', '0x6d6d6d', '0x6e6e6e', '0x6f6f6f', '0x707070', '0x717171', '0x727272', '0x737373', '0x747474', '0x757575', '0x767676', '0x777777', '0x787878', '0x797979', '0x7a7a7a', '0x7b7b7b', '0x7c7c7c', '0x7d7d7d', '0x7e7e7e', '0x7f7f7f', '0x808080', '0x818181', '0x828282', '0x838383', '0x848484', '0x858585', '0x868686', '0x878787', '0x888888', '0x898989', '0x8a8a8a', '0x8b8b8b', '0x8c8c8c', '0x8d8d8d', '0x8e8e8e', '0x8f8f8f', '0x909090', '0x919191', '0x929292', '0x939393', '0x949494', '0x959595', '0x969696', '0x979797', '0x989898', '0x999999', '0x9a9a9a', '0x9b9b9b', '0x9c9c9c', '0x9d9d9d', '0x9e9e9e', '0x9f9f9f', '0xa0a0a0', '0xa1a1a1', '0xa2a2a2', '0xa3a3a3', '0xa4a4a4', '0xa5a5a5', '0xa6a6a6', '0xa7a7a7', '0xa8a8a8', '0xa9a9a9', '0xaaaaaa', '0xababab', '0xacacac', '0xadadad', '0xaeaeae', '0xafafaf', '0xb0b0b0', '0xb1b1b1', '0xb2b2b2', '0xb3b3b3', '0xb4b4b4', '0xb5b5b5', '0xb6b6b6', '0xb7b7b7', '0xb8b8b8', '0xb9b9b9', '0xbababa', '0xbbbbbb', '0xbcbcbc', '0xbdbdbd', '0xbebebe', '0xbfbfbf', '0xc0c0c0', '0xc1c1c1', '0xc2c2c2', '0xc3c3c3', '0xc4c4c4', '0xc5c5c5', '0xc6c6c6', '0xc7c7c7', '0xc8c8c8', '0xc9c9c9', '0xcacaca', '0xcbcbcb', '0xcccccc', '0xcdcdcd', '0xcecece', '0xcfcfcf', '0xd0d0d0', '0xd1d1d1', '0xd2d2d2', '0xd3d3d3', '0xd4d4d4', '0xd5d5d5', '0xd6d6d6', '0xd7d7d7', '0xd8d8d8', '0xd9d9d9', '0xdadada', '0xdbdbdb', '0xdcdcdc', '0xdddddd', '0xdedede', '0xdfdfdf', '0xe0e0e0', '0xe1e1e1', '0xe2e2e2', '0xe3e3e3', '0xe4e4e4', '0xe5e5e5', '0xe6e6e6', '0xe7e7e7', '0xe8e8e8', '0xe9e9e9', '0xeaeaea', '0xebebeb', '0xececec', '0xededed', '0xeeeeee', '0xefefef', '0xf0f0f0', '0xf1f1f1', '0xf2f2f2', '0xf3f3f3', '0xf4f4f4', '0xf5f5f5', '0xf6f6f6', '0xf7f7f7', '0xf8f8f8', '0xf9f9f9', '0xfafafa', '0xfbfbfb', '0xfcfcfc', '0xfdfdfd', '0xfefefe', '0xffffff']

and i looks like:

[0, 65793, 131586, 197379, 263172, 328965, 394758, 460551, 526344, 592137, 657930, 723723, 789516, 855309, 921102, 986895, 1052688, 1118481, 1184274, 1250067, 1315860, 1381653, 1447446, 1513239, 1579032, 1644825, 1710618, 1776411, 1842204, 1907997, 1973790, 2039583, 2105376, 2171169, 2236962, 2302755, 2368548, 2434341, 2500134, 2565927, 2631720, 2697513, 2763306, 2829099, 2894892, 2960685, 3026478, 3092271, 3158064, 3223857, 3289650, 3355443, 3421236, 3487029, 3552822, 3618615, 3684408, 3750201, 3815994, 3881787, 3947580, 4013373, 4079166, 4144959, 4210752, 4276545, 4342338, 4408131, 4473924, 4539717, 4605510, 4671303, 4737096, 4802889, 4868682, 4934475, 5000268, 5066061, 5131854, 5197647, 5263440, 5329233, 5395026, 5460819, 5526612, 5592405, 5658198, 5723991, 5789784, 5855577, 5921370, 5987163, 6052956, 6118749, 6184542, 6250335, 6316128, 6381921, 6447714, 6513507, 6579300, 6645093, 6710886, 6776679, 6842472, 6908265, 6974058, 7039851, 7105644, 7171437, 7237230, 7303023, 7368816, 7434609, 7500402, 7566195, 7631988, 7697781, 7763574, 7829367, 7895160, 7960953, 8026746, 8092539, 8158332, 8224125, 8289918, 8355711, 8421504, 8487297, 8553090, 8618883, 8684676, 8750469, 8816262, 8882055, 8947848, 9013641, 9079434, 9145227, 9211020, 9276813, 9342606, 9408399, 9474192, 9539985, 9605778, 9671571, 9737364, 9803157, 9868950, 9934743, 10000536, 10066329, 10132122, 10197915, 10263708, 10329501, 10395294, 10461087, 10526880, 10592673, 10658466, 10724259, 10790052, 10855845, 10921638, 10987431, 11053224, 11119017, 11184810, 11250603, 11316396, 11382189, 11447982, 11513775, 11579568, 11645361, 11711154, 11776947, 11842740, 11908533, 11974326, 12040119, 12105912, 12171705, 12237498, 12303291, 12369084, 12434877, 12500670, 12566463, 12632256, 12698049, 12763842, 12829635, 12895428, 12961221, 13027014, 13092807, 13158600, 13224393, 13290186, 13355979, 13421772, 13487565, 13553358, 13619151, 13684944, 13750737, 13816530, 13882323, 13948116, 14013909, 14079702, 14145495, 14211288, 14277081, 14342874, 14408667, 14474460, 14540253, 14606046, 14671839, 14737632, 14803425, 14869218, 14935011, 15000804, 15066597, 15132390, 15198183, 15263976, 15329769, 15395562, 15461355, 15527148, 15592941, 15658734, 15724527, 15790320, 15856113, 15921906, 15987699, 16053492, 16119285, 16185078, 16250871, 16316664, 16382457, 16448250, 16514043, 16579836, 16645629, 16711422, 16777215]

Comments

1

You can use the hex() built-in function instead of int() in order to convert your integer number to hex.

Comments

1

just 2 line of code:

for i in range(0,256):
    print('%02X%02X%02X' % (i,i,i), sep="")

Output:

000000 010101 020202 030303 040404 050505 060606 070707 080808 090909 
0A0A0A 0B0B0B 0C0C0C 0D0D0D 0E0E0E 0F0F0F ....

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.