Decimal to Hex Converter

A decimal whole number as hex and binary, side by side.

Result

0xBEE
101111101110

How it is calculated

The tool takes a non-negative whole number and shows it in base 16 and base 2. The hex digits are found by repeated division: n = 16 × q + r, where each remainder r (0 to 15, with 10 to 15 written A to F) is one hex digit, read from the last remainder back to the first. The result is shown with an 0x prefix and upper-case letters; the binary result has no prefix and no leading zeros. Zero returns 0x0 and 0. Negative numbers, numbers with a fractional part (such as 10.5) and numbers containing a comma such as 1,000 give no result, and so does anything larger than 253 (9007199254740992), the largest range the tool can hold exactly. It does not produce two's-complement forms for negatives.

Worked example

Convert 3054. Dividing by 16: 3054 = 16 × 190 + 14, so the last hex digit is E. Then 190 = 16 × 11 + 14, giving another E. Finally 11 is below 16, so it is the leading digit B. Reading the remainders back gives 0xBEE. Replacing each hex digit with 4 bits (B = 1011, E = 1110, E = 1110) gives the binary form 101111101110.

Try this example →

Common mistakes

  • Entering a negative number and expecting a two's-complement result such as FFFFFFFB for −5. Negative input is rejected.
  • Typing a decimal fraction like 10.5, or a value with a comma like 1,000, which is rejected. A dot is always a decimal point, so 1.000 is read as 1, not one thousand; type 1000.
  • Reading the result as a pair of bytes when the digit count is odd. 0xBEE is three digits, so as bytes it is 0x0BEE; pad with a leading zero when a byte-aligned value is needed.
  • Mixing up the digits after 9. A is 10, B is 11 and F is 15, so 0x1F is 31, not 1 followed by 15 as separate decimal numbers.
  • Entering integers near or above 253 and trusting every digit. At that size ordinary number precision runs out, so keep values below about 15 digits when you need an exact conversion.

About this calculator

Hexadecimal (base 16) uses digits 0-9 and letters A-F, and it's the standard way programmers represent binary data compactly because each hex digit maps to exactly 4 bits — so a byte (8 bits) is always exactly two hex digits (00 to FF), whereas in decimal the same byte takes anywhere from one to three digits (0 to 255) that don't line up with its bits. Converting decimal to hex means repeatedly dividing by 16 and reading the remainders in reverse, while decimal to binary is the same process dividing by 2.

Software developers, systems programmers, and web designers use hex constantly — for memory addresses and pointers, byte values in a debugger, CSS colour codes (#RRGGBB), and error/status codes — because it's dramatically shorter to read and write than the equivalent binary while still mapping cleanly onto binary structure.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    For colour codes, convert each channel from 0 to 255 on its own and pad to two digits yourself, because the tool prints 0xA for 10, not 0A. It handles non-negative whole numbers up to 2 to the power 53, so negatives, which would need two's complement, are not supported. Do you need fixed-width output, such as 8 or 16 bits, or two's complement? Tell us which you would use.

Popular calculators

All Calculators