How to convert any integer number to hexadecimal number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to convert any integer number to hexadecimal number?

Please explain it in a easy way & give some example

21st Jun 2020, 10:44 AM
Ashik Ahmed
Ashik Ahmed - avatar
10 Answers
+ 11
[Python] You can just use hex(). To convert a string to base 10 from another base you can use the second parameter of int(). print(hex(255)) # output 0xff print(int("ff", 16)) # output 255 or using input(): print(hex(int(input()))) print(int(input(), 16)) # inputting ff or 0xff gives same result
21st Jun 2020, 1:15 PM
David Ashton
David Ashton - avatar
+ 9
In python, Hex numbers can also be created for output with print() and format string: inp = 200 print(f'dec: {inp:3d}, hex: {inp:3X}') # output: dec: 200, hex: C8 # or a string can be generated for further use: h_res = f'{inp:X}' # h_res : 'C8'
21st Jun 2020, 12:15 PM
Lothar
Lothar - avatar
+ 9
Lothar he is asking in c language ....🤣
23rd Jun 2020, 6:13 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 9
Oma Falk 😅🤣🤣 he mention in tag so
23rd Jun 2020, 7:50 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 6
divide by 16 and write down rest. 200 200/16 = 12 remainder 8 12/16 = 0 remainder 12 aka c result c8
21st Jun 2020, 11:04 AM
Oma Falk
Oma Falk - avatar
+ 5
23rd Jun 2020, 7:46 AM
Oma Falk
Oma Falk - avatar
+ 4
23rd Jun 2020, 9:09 AM
Oma Falk
Oma Falk - avatar
+ 3
21st Jun 2020, 4:54 PM
Oma Falk
Oma Falk - avatar
+ 1
Martin Taylor
22nd Jun 2020, 10:59 AM
Ashik Ahmed
Ashik Ahmed - avatar
0
Divide that number by it's base which is 16..as we do for converting decimal to binary since the base of binary is 2 that's why we divide it by 2...do the same for it also..use base 16 instead of 2
23rd Jun 2020, 9:45 AM
_-_-_-_
_-_-_-_ - avatar