Convert Decimal to Hex

Enter your decimal numbers below—one per line—and get instant hexadecimal conversions. Whether you're working with CSS color codes, debugging memory addresses, or converting values for low-level programming, this tool handles all your base-16 conversion needs.

DECIMAL

Enter decimal numbers to convert

HEXADECIMAL

Outputs hexadecimal (base-16) representation

Loading converter...

How to convert Decimal to Hexadecimal - a step by step tutorial

Master the division-by-16 method with step-by-step examples. Learn place values, remainder extraction, and common pitfalls when converting base-10 to base-16 numbers.

How to Use This Converter

1

Enter Decimal Value

Type any base-10 number: RGB values, memory addresses, or API responses

2

Instant Hex Output

Get hexadecimal instantly—perfect for CSS colors or printf formatting

3

Copy for Code

Use in JavaScript, Python, C, or any programming language

4

Format Options

Add 0x prefix, uppercase, or padding for your needs

Decimal to Hex Conversion Examples

Common decimal values developers encounter daily, converted to hexadecimal for CSS, programming, and system-level work.

Decimal InputHex OutputCommon Use Case
2550xFFMaximum byte value, RGB color channel max
1280x80Half byte value, common RGB midpoint
167772150xFFFFFFWhite color (RGB: 255, 255, 255)
40960x1000Common buffer size, 4 KB
655350xFFFFMax 16-bit unsigned integer, port number max
10240x4001 KB, common memory chunk size
1270x7FMax signed byte, ASCII character range max
2560x100One byte + 1, first 3-digit hex

What is Decimal to Hex Conversion?

Decimal to hex conversion transforms base-10 numbers into base-16 hexadecimal format, essential for web development, systems programming, and debugging. CSS color codes rely entirely on hex—converting RGB decimal values (red: 255, green: 128, blue: 64) produces #FF8040 for styling. Memory addresses in debuggers display as hex (0x7FFF5FBFF8AC), requiring decimal conversion to calculate offsets or understand pointer arithmetic. API responses sometimes return numeric IDs that developers convert to hex for logging, database indexing, or protocol compliance where hexadecimal provides compact representation.

Programming languages provide native decimal-to-hex conversion methods: JavaScript's toString(16), Python's hex(), C's printf("%X"), and Java's Integer.toHexString(). Game developers convert decimal asset IDs to hex for efficient storage and lookup. Network engineers transform decimal IP address octets and port numbers to hex for packet analysis. Understanding decimal-to-hex conversion enables developers to read memory dumps, interpret binary file formats, and work with low-level system APIs that expect hexadecimal input. For reverse conversion, use our Hex to Decimal converter.

Programming with Hex: Decimal Conversion Guide

Convert decimal to hexadecimal in popular programming languages—copy-paste ready code examples for JavaScript, Python, C, Java, and more.

JavaScript / TypeScript

// Convert decimal to hex
let dec = 255;
let hex = dec.toString(16);
// "ff"
let hexUpper = dec.toString(16).toUpperCase();
// "FF"
let hexPrefixed = '0x' + hex;
// "0xff"

Python

# Convert decimal to hex
dec = 255
hex_val = hex(dec)
# '0xff'
hex_no_prefix = hex(dec)[2:]
# 'ff'
hex_upper = format(dec, 'X')
# 'FF'

C / C++

// Convert decimal to hex
int dec = 255;
printf("0x%X", dec);
// Prints: 0xFF
printf("%x", dec);
// Prints: ff

Java

// Convert decimal to hex
int dec = 255;
String hex = Integer.toHexString(dec);
// "ff"
String hexUpper = hex.toUpperCase();
// "FF"
💡 Pro Tip: When working with CSS colors, remember to pad single-digit hex values with leading zeros. RGB(5, 10, 15) should be #050A0F, not #50AF.

Common Use Cases for Decimal to Hex

🎨

Web Development & CSS

  • • Convert RGB to hex color codes
  • • Generate CSS color palettes
  • • Debug computed style values
  • • Create design system colors
💻

Systems Programming

  • • Format memory addresses
  • • Debug pointer values
  • • Convert file permissions (chmod)
  • • Parse binary file formats
🎮

Game Development

  • • Convert Unity color values
  • • Format asset ID lookups
  • • Optimize memory allocation
  • • Debug shader hex values

Decimal to Hex Converter Features

🎨

CSS Color Generator

Convert RGB values to perfect hex color codes

💻

Developer-Friendly

Copy-paste ready for all programming languages

Instant Results

Real-time conversion as you type

🔧

Format Options

0x prefix, uppercase, zero-padding available

📋

Large Numbers

Handle values up to JavaScript max safe integer

🎯

Accurate

Precision decimal to hex conversion

Understanding Base-10 to Base-16 Conversion

Decimal (base-10) uses digits 0-9 with positional values as powers of 10: the number 158 means (1×10²)+(5×10¹)+(8×10⁰) = 100+50+8. Hexadecimal (base-16) extends this with digits 0-9 and letters A-F (representing 10-15), where positional values are powers of 16. Converting decimal 158 to hex requires dividing by 16 repeatedly: 158÷16=9 remainder 14 (E), 9÷16=0 remainder 9, reading remainders bottom-up gives 9E. This division method works because hex position values increase by factors of 16—the rightmost digit represents ones (16⁰), next represents sixteens (16¹), then 256s (16²), and so on.

CSS color codes demonstrate practical decimal-to-hex conversion: RGB(255, 128, 64) requires converting each channel separately. Red 255 becomes FF (15×16 + 15), green 128 becomes 80 (8×16 + 0), blue 64 becomes 40 (4×16 + 0), combining to #FF8040. Web browsers accept both formats but hex provides compactness—6 characters versus "rgb(255,128,64)" at 16 characters. The toString(16) method in JavaScript handles this automatically, but understanding the math helps debug color conversion issues when values don't match expectations.

Memory addresses and pointers in C/C++ display as hex because computer memory organizes in powers of 2, and hex maps cleanly to binary (each hex digit = 4 bits). An address like 0x7FFF5FBFF8AC represents decimal 140,734,647,320,748, but hex conveys the bit pattern more intuitively for debugging. File permissions in Unix/Linux use octal (base-8) but hex equivalents help: permission 755 (octal) equals 0x1ED (hex) equals 493 (decimal). Understanding base conversion unlocks low-level programming, networking protocols, and embedded systems development. For converting hex back to decimal, use our Hex to Decimal converter.

Frequently Asked Questions

How do I convert decimal to hex in JavaScript?

Use number.toString(16) method. Example: 255.toString(16) returns "ff". Add .toUpperCase() for capital letters: "FF". Prefix with "0x" if needed.

What hex value is RGB color (255, 128, 0)?

Convert each channel separately: 255→FF, 128→80, 0→00, resulting in #FF8000 (orange). Each RGB channel ranges 0-255 decimal, which maps to 00-FF hex. Use our converter for quick RGB to hex color codes.

Why do CSS colors use hex instead of decimal?

Hex provides compact notation: #FF8040 is 7 characters versus rgb(255,128,64) at 16 characters. Historically, hex aligned with how computers store color in memory (bytes), and the format became standard before CSS rgb() syntax existed.

How to convert negative decimal numbers to hex?

Negative numbers use two's complement representation. In JavaScript, use (-10 >>> 0).toString(16) for unsigned conversion. Result depends on bit width (8-bit, 16-bit, 32-bit). -1 in 8-bit hex is 0xFF.

What's the hex equivalent of 1 million?

1,000,000 decimal converts to 0xF4240 hexadecimal. Calculate: 1,000,000÷16=62,500 R 0, continue dividing and reading remainders backward. Useful for understanding large memory allocations or file sizes in hex.

How to pad hex with leading zeros?

In JavaScript: num.toString(16).padStart(2, '0') ensures 2-digit hex (5 becomes "05"). In Python: format(num, '02X'). Essential for CSS colors where #050A0F requires padding, not #50AF.

Convert hexadecimal numbers to decimal numbers.

Convert binary numbers to hexadecimal numbers.

Convert octal numbers to hexadecimal values.

Convert an RGB color to a hexadecimal color.

DECIMAL to hex conversion table.

HEX to decimal conversion table.


Have feedback or questions?

Please, do let us know and we'll see what we can do for you.

0/2000