Decimal to Hexadecimal Converter
Convert decimal integers to hex, including negative numbers (Two"s Complement). Select output bit-width (8/16/32-bit) for CSS colors or memory addressing analysis.
About
Web developers and system programmers often move between human-readable base-10 integers and machine-oriented hexadecimal values. Whether you are calculating CSS color codes (e.g., RGB values 0-255) or debugging memory offsets, this conversion is daily routine. A critical feature of this tool is the correct handling of negative numbers using Two"s Complement representation, mimicking how CPUs store signed integers in memory.
The interface allows you to constrain the output to specific bit widths (8-bit, 16-bit, 32-bit), showing exactly how a number like -1 appears as FF, FFFF, or FFFFFFFF depending on the allocated storage.
Formulas
For positive integers, the conversion uses repeated division by 16.
x = q × 16 + r
Where r is the hex digit.
For negative integers (Two"s Complement) with bit-width n:
Hex = (x + 2n) mod 2n
Reference Data
| Decimal | Hex (8-bit) | Hex (16-bit) | Use Case |
|---|---|---|---|
| 0 | 00 | 0000 | Zero |
| 10 | 0A | 000A | LF (Line Feed) |
| 127 | 7F | 007F | Max signed 8-bit |
| 255 | FF | 00FF | Max unsigned 8-bit / White (RGB) |
| -1 | FF | FFFF | Two"s Complement |
| 4096 | Overflow | 1000 | Page size |
| 65535 | Overflow | FFFF | Max unsigned 16-bit port |