Formula
Place value. Each digit is worth the base raised to its position. The converter parses by hand, including bases other than the ones JavaScript’s own integer reader accepts, and it rejects a digit that does not belong in the base.
value = Σ digit × base^position
two’s complement = the low bits of the number, width you chose
Binary is grouped by fours so a long string can be read. The grouping does not change the value.
Worked examples
255 decimal. Hex FF. Binary 11111111, grouped 1111 1111. In 8 bits the two’s-complement form is the same, because 255 does not fit in a signed 8-bit range. The warning says so.
−1 in 8 bits. Two’s complement is 11111111. Adding one to that byte wraps to 0.
Reference
| Decimal | Hex | Binary |
|---|---|---|
| 255 | ff | 1111 1111 |
| 42 | 2a | 0010 1010 |
| 16 | 10 | 0001 0000 |
| −1, 8-bit two’s | — | 11111111 |
Questions
How do you convert decimal to hexadecimal?
Divide by 16 and read the remainders from the bottom. 255 is 15 sixteens with remainder 15, which is FF. 42 is 2A. This page does the same division for binary and octal.
How do you convert decimal to binary?
Divide by 2 and keep the remainders. 255 is 11111111. The grouped view inserts a space every four bits, which is the same number. 42 is 0010 1010 once it is padded to a nibble.
What is two’s complement?
A fixed-width reading of a signed integer. In 8 bits, −1 is 11111111, because adding one wraps to zero. The width is 8, 16, 32, or 64. A number that does not fit is shown masked to that width, with a warning.
Which old converter URLs land here?
The previous site’s decimal-to-binary, decimal-to-hex, and conversion-calculator pages now redirect here. Currency conversion is not on this site.
Sources
- Place-value conversion. Hex digits continue A = 10 through F = 15. Two’s complement is the low bits of a fixed width: in 8 bits, −1 is 11111111.