answersLogoWhite

0


Best Answer

In a programming sense or a mathematical sense?

Mathematically, it is the same method as used to convert between any number bases:

Divide the number by the new base and note the remainder. Repeat with the quotient until it is zero. The number in the new base is the remainders in reverse order. For example, to convert the number 1234 in decimal (base 10) to hexadecimal (base 16):

1234 / 16 = 77 r2

77 / 16 = 4 r13

4 / 16 = 0 r 4

Number bases less than 10 use the same decimal digits, eg octal numbers (base 8) use the digits 0-7. For bases greater than 10, the convention is to use the alphabet to represent the extra digits, so base 11 would use 0-9,A, base 12 0-9, A-B, base 16 0-9, A-F, etc (where A would represent 1010, B represent 1110, etc).

so 123410 = 4D216.

Programmingwise, it would depend up on how your input number is stored, along with the language you're using. In C, for example, if you have an int containing number, it is actually effectively stored in binary and when printing it (converting to a string) it is converted to whatever the printf specification requests:

printf("%d = 0x%x", 1234, 1234);

would display

1234 = 0x4d2

The same specifications can be used on sprintf to store the result in memory.

If you are required to write the conversion, program the algorithm described in the mathematical method.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you convert a number to hexadecimal form?
Write your answer...
Submit
Still have questions?
magnify glass
imp