Decimal to hexadecimal
By Oakgen Team · Updated
Divide the number by 16 repeatedly and read the remainders from last to first, using A to F for 10 to 15. For 500: 500 ÷ 16 = 31 r 4, 31 ÷ 16 = 1 r 15 (F), 1 ÷ 16 = 0 r 1, so 500 is 1F4.
Decimal to Hexadecimal
Hexadecimal
| Power | Decimal value | Hex |
|---|---|---|
| 16^0 | 1 | 1 |
| 16^1 | 16 | 10 |
| 16^2 | 256 | 100 |
| 16^3 | 4096 | 1000 |
| 16^4 | 65536 | 10000 |
The repeated-division method
Divide the decimal number by 16. The remainder (0 to 15) is the next hex digit from the right. Divide the quotient by 16 again and repeat until the quotient is 0. Read the remainders from the last one to the first.
Example, 500: 500 ÷ 16 = 31 remainder 4; 31 ÷ 16 = 1 remainder 15, written F; 1 ÷ 16 = 0 remainder 1. Reading upward gives 1F4. Check: 1×256 + 15×16 + 4 = 500. Another: 255 is FF, and 4,095 is FFF.
Padding to whole bytes
Because two hex digits make one byte, data is usually written with an even number of digits. 10 in hex is A, but as a byte it is 0A. When you need a fixed width, pad with leading zeros: 16-bit values use four digits and 32-bit values use eight.
Limits and negative numbers
This converter accepts whole numbers of 0 or more and uses arbitrary-size integers, so large values are exact. Negative numbers have no single hex form: signed values are stored in a fixed width (two's complement), and the hex digits depend on the width you choose.
Do more with Oakgen Agent
The Agent can convert a whole list in its code sandbox, pad the results to the width you choose, and return a table or CSV.
Open in Oakgen AgentThe prompt is filled in for you. Nothing is sent until you press send in the Agent.
FAQ
What is 255 in hex?
255 is FF: 15 sixteens plus 15 ones.
What is 100 in hex?
100 is 64 in hex: 6×16 + 4.
Why do hex numbers use letters?
Base 16 needs sixteen distinct digits. 0 to 9 cover ten of them, so A to F stand for 10 to 15.
How do I turn the result into binary?
Write each hex digit as four bits. 1F4 becomes 0001 1111 0100.