❯serpapisget_key()

$ man hex-to-decimal-converter

Hex To Decimal Converter

NAME

hex-to-decimal-converter — Convert hex to decimal and decimal to hex exactly, up to 64-bit values. Shows the 16-power working, binary and octal, and the signed two's-complement reading.

SYNOPSIS

# What is a hex to decimal converter?
A hex to decimal converter turns a base-16 number such as 1A or DEADBEEF into its base-10 value, and converts decimal back to hex, showing the column working and the signed and unsigned readings of the same bit pattern.

WHY HERE

Number-base and data utilities for developers working with APIs.

./hex-to-decimal-converter --interactive
0x, # and a trailing h are stripped. Digits 0-9 and A-F.
For the signed reading.
Decimal value260x1A in base 16
Hexadecimal1A
Decimal26
Binary11010
Octal32
Unsigned (32-bit)26
Signed two's complement (32-bit)26
Bits needed5 (1 byte)
DigitValueColumnDigit × column
1116^1 = 1616
A1016^0 = 110

USAGE

  1. 01 → Paste the number

    A leading 0x, a leading # and a trailing h are all stripped for you, so you can paste straight out of code, a CSS colour or an assembly listing. Spaces and underscores between digits are ignored, which means a hex dump like "de ad be ef" pastes fine.

  2. 02 → Choose the direction

    Hex to decimal reads your input as base 16; decimal to hex reads it as base 10. Getting this backwards is the commonest mistake, and it is silent when your input happens to be all digits: 1024 is a legal hex number as well as a legal decimal one, and the two answers are 4,132 and 400 respectively.

  3. 03 → Set the word width if the value came from code

    Hex out of a debugger is a machine word, and 0xFF means 255 in a uint8 but -1 in an int8. Pick 8, 16, 32 or 64 bits to match the type you are reading, and the signed and unsigned values are both shown. Pick the width from the declaration, not from how many digits the value happens to have.

  4. 04 → Check the column working

    The table multiplies each digit by its power of sixteen so you can see where the answer came from and show it in homework. Remember the digits run A=10 to F=15; writing F as 16 is the other classic slip.

DESCRIPTION

Hexadecimal is base 16, so each column is worth sixteen times the one to its right: 1, 16, 256, 4096 and so on. Converting to decimal is therefore just a weighted sum. Take 1A: the 1 sits in the sixteens column and the A is worth ten, so 1 x 16 + 10 x 1 = 26. DEADBEEF is the same idea with eight columns: D(13) x 16^7 down to F(15) x 16^0, which comes to 3,735,928,559. Going the other way, as a decimal to hex converter, you divide repeatedly by 16 and read the remainders bottom-up, which is exactly what the digits in the output represent.

Hex exists because of binary, not in spite of it. One hex digit is exactly four bits, so a byte is always exactly two hex digits and converting between hex and binary is a lookup rather than arithmetic. That is why memory addresses, colour codes, MAC addresses and file magic numbers are all written in hex: 11011110 is hard to read and DE is not. The binary line in the output is grouped so you can see the four-bit nibbles line up with the hex digits.

The trap that catches working programmers is sign. A hex literal is a bit pattern, and whether it means a large positive number or a small negative one depends entirely on the type it is stored in. 0xFFFF is 65,535 as a uint16 and -1 as an int16; 0x80000000 is 2,147,483,648 unsigned and -2,147,483,648 as a 32-bit int. The rule is two's complement: if the top bit of the word is set, subtract 2 to the power of the word width. This tool shows both readings side by side rather than picking one, because only your variable declaration knows which is right.

Exactness matters above 2^53, which is about sixteen decimal digits. Anything that converts hex by way of a JavaScript number quietly rounds a 64-bit value, so 0xFFFFFFFFFFFFFFFF comes back as 18,446,744,073,709,552,000 instead of ...551,615. The conversion here carries the integer part as an arbitrary-precision integer, so a full 64-bit word converts digit for digit. Fractional hex works too: 0x1.8 is 1.5, because the first place after the point is worth one sixteenth.

FAQ

## How do you convert hex to decimal by hand?

Number the digits from the right starting at zero, multiply each digit by 16 raised to that position, and add the results. For 2F3: 2 x 256 + 15 x 16 + 3 x 1 = 512 + 240 + 3 = 755. The column table in the tool shows exactly this working.

## What is FF in decimal?

255 read as an unsigned byte, which is the largest value two hex digits can hold. Read as a signed 8-bit integer the same bit pattern is -1, because the top bit is set. Both are shown so you can take the one that matches your type.

## How do I convert decimal to hex?

Divide by 16 repeatedly and read the remainders from last to first, writing 10 to 15 as A to F. 255 gives remainder 15 (F) then 15 (F), so FF. Switch the direction toggle and the tool does it for you.

## Why does my 16-digit hex value come out wrong in other converters?

Because they convert through a double-precision float, which is only exact to 2^53 — roughly nine quadrillion. Past that the low digits are rounded away. This converter uses arbitrary-precision integers, so a full 64-bit word is exact.

## Is hex case sensitive?

No. 0xdeadbeef and 0xDEADBEEF are the same number. Lower case is the C and Unix convention, upper case the convention in Windows and in most hardware documentation; the output toggle covers both.