0

Please how else can I convert an integer to hexadecimal in python. I tried hex(2356) but I got an error message.

python tutorial question https://code.sololearn.com/cx9Z2vh7Atgc/?ref=app https://www.sololearn.com/discuss/1068064/?ref=app

21st Feb 2018, 10:58 AM
Adisa Olaitan
4 Answers
+ 6
Should work fine, I think. print(hex(2356)) 0x934
21st Feb 2018, 11:13 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
you can do it manually by storing the remainder of that integer by 16 and then dividing it by 16 in a loop: var res=""; var int; while (int>0){ res = int%16 + res; int /= 16; } also note that your integer should not be greater than 16,777,216 and the division should give you an integer without decimal
21st Feb 2018, 11:43 AM
Dominique Abou Samah
Dominique Abou Samah - avatar
+ 1
also check out my code in javascript where i do just that https://code.sololearn.com/W805C9p2MN3x/?ref=app
21st Feb 2018, 11:43 AM
Dominique Abou Samah
Dominique Abou Samah - avatar
0
I have tried that as well but it didn't work
21st Feb 2018, 11:24 AM
Adisa Olaitan