Guide

How to Convert Decimal to Hexadecimal

Hexadecimal is base 16. Divide by 16 repeatedly and read the remainders backwards.

Updated

Try it now: Decimal to Hex Converter. It runs in your browser, with no signup.

The digits

Base 16 needs sixteen symbols, so after 9 it continues with the letters A to F.

Decimal:  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hex:      0 1 2 3 4 5 6 7 8 9 A  B  C  D  E  F

Method: repeated division

Divide the number by 16, write down the remainder, then divide the quotient by 16 again. Stop when the quotient is 0. The hex number is the remainders read from last to first.

3054 / 16 = 190 remainder 14  (E)
 190 / 16 =  11 remainder 14  (E)
  11 / 16 =   0 remainder 11  (B)

read backwards: BEE   ->   3054 = 0xBEE

255 / 16 = 15 remainder 15 (F), 15 / 16 = 0 remainder 15 (F)  ->  FF

Check it by converting back

Multiply each digit by a power of 16 and add: BEE = 11 * 256 + 14 * 16 + 14 = 2816 + 224 + 14 = 3054.

Code

JavaScript numbers lose precision above 2^53 - 1 (9007199254740991), so use BigInt for large values.

// JavaScript
(255).toString(16);              // "ff"
parseInt("ff", 16);              // 255
BigInt("18446744073709551615").toString(16);   // "ffffffffffffffff"

# Python
hex(255)                         # "0xff"
int("ff", 16)                    # 255

// C#
255.ToString("X");               // "FF"
Convert.ToInt32("FF", 16);       // 255

Negative numbers and prefixes

Use the Decimal to Hex Converter for quick checks, or the Number Base Converter to see binary, octal, decimal and hex together.

  • Hex has no sign of its own. Negative integers are shown in two's complement for a fixed width: -1 as a 32-bit value is FFFFFFFF.
  • Code usually writes hex with a prefix: 0xFF in C, C#, Java and JavaScript, #FF in CSS colours.
  • Pad to a fixed width when you need it, for example 0A rather than A for one byte.

Frequently asked questions

What is 255 in hex?

FF. It is 15 * 16 + 15, and it is the largest value of one byte.

Why do programmers use hex?

One hex digit is exactly four bits, so a byte is always two digits. That makes memory values, colours and hashes compact and easy to read.

How do I convert hex to decimal?

Multiply each digit by a power of 16 and add the results, or use parseInt(value, 16) in JavaScript.

Tools used in this guide

onlinedevelopertool.com is a collection of 54 free, browser-based utilities for the small jobs that interrupt real work: formatting a JSON response, decoding a token, converting a timestamp, generating a UUID or checking a hash. Each tool has its own page with a short explanation, a worked example and answers to common questions, so you can use it and learn what it does at the same time.

There is no account to create and nothing to install. Tools run in your browser, so the text you paste is processed on your own device. The one exception is the Website Status Checker, which sends a request from your browser to the address you enter.

Three steps: paste your input, click the tool, copy the result, all inside your browser
Popular developer utilities: JWT decoder, UUID generator, Base64 decoder, SHA-256 hash, regex tester and timestamp converter

What you can do here

  • JSON Tools

    Format, validate, beautify and minify JSON, generate C#, TypeScript, Java, Python, Go, PHP and Kotlin models from it, or convert between JSON, YAML and CSV.

  • Encoders & Decoders

    URL, Base64 and HTML encoding and decoding, plus a JWT decoder for reading token claims.

  • Generators & Hashes

    Generate UUIDs and JWTs, validate UUIDs, and create MD5, SHA-256 and SHA-512 hashes.

  • Web Tools

    Timestamps, color codes, query strings and cron expressions - the small things web work keeps throwing at you.

  • Text & Data

    Format XML and YAML, count text, change case, make slugs, test regex, diff two texts and convert number bases.

  • Website Checking

    Check whether a website or URL is reachable from your browser.

Quick developer reference

  • JSON

    Keys and strings must use double quotes, and trailing commas and comments are not allowed. Those are the three most common reasons a payload fails to parse.

    Validate JSON
  • JWT

    A JSON Web Token is three Base64URL parts joined by dots: header, payload and signature. Decoding shows the claims but does not prove the token is genuine; only signature verification does.

    Decode a JWT
  • Base64

    Base64 is an encoding, not encryption. Anyone can reverse it, and it makes data roughly one third larger, so never use it to hide secrets.

    Decode Base64
  • UUID

    A version 4 UUID is made of random bits and written as 8-4-4-4-12 hexadecimal characters. Collisions are astronomically unlikely, which is why they work well as identifiers.

    Generate a UUID
  • Timestamps

    A Unix timestamp counts time since 1 January 1970 UTC. Ten digits usually means seconds and thirteen digits usually means milliseconds.

    Convert a timestamp
  • Hashes

    MD5 is fine for quick checksums but is not safe for security. Prefer SHA-256 or SHA-512, and remember that hashing is one-way and is not encryption.

    Create a SHA-256 hash

Missing a tool you need? Visit the contact page and tell us what you reach for most often. You can also browse every tool or read the About page to see how the site is built and what it does with your data.