DevToolBox

Hex to Decimal - 16進数と10進数の変換方法と早見表

最終更新日: 2026-07-11公開日: 2026-07-11執筆: DevToolBox編集部

0x1A#FF5733 のような16進数表記を見て、頭の中でとっさに10進数へ 変換できず手が止まった経験はないでしょうか。16進数(hex)から10進数(decimal)への変換は、各桁に16の累乗を掛けて合計するだけの単純な仕組みです。この記事では手計算の手順、 逆方向(10進数→16進数)の求め方、0〜255の早見表、主要言語での convert to hexadecimalコード例までをまとめます。

Converting hex to decimal is just place-value math: multiply each digit by a power of 16 and sum the results. This guide walks through the hand-calculation method both directions, a lookup table for 0-255, and how to convert to hexadecimal (and back) in five programming languages.

TL;DR

Number Base Converter

2進数・8進数・10進数・16進数を相互変換。桁数の大きい数値もBigInt対応で正確に計算し、4進数まとめて一覧表示します。ブラウザ完結・外部送信なし。

今すぐ試す →

1. 16進数の位取りのしくみ / How place value works in hex

10進数が「0〜9の10種類の記号」で位取りするのに対し、16進数は「0〜9とA〜Fの16種類の記号」で位取りします。 10進数の各桁が10の累乗(1, 10, 100…)の重みを持つのと同じように、16進数の各桁は16の累乗(1, 16, 256, 4096…)の重みを持ちます。A=10、B=11、C=12、D=13、E=14、F=15です。

decimal:  1 2 3   → 1×10^2 + 2×10^1 + 3×10^0 = 100 + 20 + 3 = 123
hex:      1 2 3   → 1×16^2 + 2×16^1 + 3×16^0 = 256 + 32 + 3 = 291

Decimal digits carry weights of powers of 10; hex digits carry weights of powers of 16. The letters A-F stand in for the single-digit values 10-15 so that base 16 still uses one character per digit.

2. 16進数→10進数への手計算 / Hex to decimal by hand

右端の桁を160(=1)として、左に行くほど161、162…と重みを増やしながら 各桁の値を掛けて合計します。

1A (hex) → 1×16^1 + 10×16^0 = 16 + 10 = 26 (decimal)
FF (hex) → 15×16^1 + 15×16^0 = 240 + 15 = 255 (decimal)
2F3 (hex) → 2×16^2 + 15×16^1 + 3×16^0 = 512 + 240 + 3 = 755 (decimal)

FF255 になるのは偶然ではありません。16進数2桁で表現できる最大値は 常に 16^2 - 1 = 255 であり、これが「1バイト = 0〜255」という表現と一致する理由です。

3. 10進数→16進数への手計算 / Decimal to hex by hand

逆方向は「16で割り続け、余りを下から順に並べる」方法が最も機械的です。商が0になるまで繰り返します。

200 を16進数に変換:
200 ÷ 16 = 12 余り 8
 12 ÷ 16 =  0 余り 12 (= C)

余りを下から上に読む → C8
検算: 12×16 + 8 = 192 + 8 = 200 ✓

To convert to hexadecimal from decimal, repeatedly divide by 16 and collect the remainders from last to first. Reading them bottom-up gives the hex digits; verify by multiplying back.

4. 早見表 / Lookup table

10進数 / Dec16進数 / Hex2進数 / Bin (4bit)
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
10A1010
11B1011
12C1100
13D1101
14E1110
15F1111

実務でよく見かける値もまとめておきます。

10進数 / Dec16進数 / Hex用途 / Where it shows up
1610基数そのもの
255FF1バイトの最大値、RGBの255,255,255
2561001バイトの取りうる値の個数
4096100016進3桁の桁上がり(16^3)
65535FFFF符号なし16bit整数の最大値、ポート番号の上限
16777215FFFFFFCSSカラーコード#FFFFFF(白)の最大値

5. 言語別コード例 / Code examples

JavaScript / TypeScript

// hex → decimal
parseInt("1A", 16);      // 26
Number("0x1A");          // 26

// decimal → hex (convert to hexadecimal)
(26).toString(16);            // "1a"
(26).toString(16).toUpperCase(); // "1A"

Python

# hex -> decimal
int("1A", 16)        # 26
int("0x1A", 16)       # 26 (0xプレフィックスも解釈可)

# decimal -> hex
hex(26)               # '0x1a'
format(26, "X")       # '1A' (プレフィックスなし・大文字)

Java

// hex -> decimal
int n = Integer.parseInt("1A", 16); // 26

// decimal -> hex
String h = Integer.toHexString(26).toUpperCase(); // "1A"

C / C++

// hex -> decimal
int n = (int)strtol("1A", NULL, 16); // 26
// printfでの直接読み取り
sscanf("1A", "%x", &n);

// decimal -> hex
printf("%X\n", 26); // "1A"

SQL (MySQL / PostgreSQL)

-- MySQL: hex -> decimal / decimal -> hex
SELECT CONV('1A', 16, 10);  -- '26'
SELECT CONV('26', 10, 16);  -- '1A'
SELECT HEX(26);              -- '1A'

-- PostgreSQL: hex -> decimal
SELECT x'1A'::int;           -- 26

6. よくある間違い / Common mistakes

なお、ここまでの数値としての変換ではなく「16進数の文字列をそのままテキストやバイト列に戻したい」 場合(例: 48 65 6c 6c 6fHello)は、数値変換ではなくHex Converter を使うのが適しています。

なぜNumber Base ConverterはBigIntを使っているか / Why our Number Base Converter uses BigInt

前段の「よくある間違い」で触れたとおり、32bit整数の範囲を超える値では桁あふれや精度低下に注意が必要です。 JavaScriptの parseIntNumber() が返す数値型は、整数を正確に表せる範囲が53bit精度の 安全な整数範囲に制約されるため、さらに桁数の大きい値では正確な変換結果を保証できません。

このサイトの /tools/number-base/ は内部で BigInt を使い、この制約に対応しています。 そのため、桁数の大きい16進数や2進数でも精度を落とさず、値を正確に相互変換できます。

JavaScript's parseInt and Number() are limited to the Number type's 53-bit safe-integer precision. Our Number Base Converter uses BigInt internally so that even very large hexadecimal and binary values can be converted without losing precision.

まとめ / Summary

hex to decimalの変換は「桁×16の累乗の合計」、逆のconvert to hexadecimalは 「16で割った余りを逆順に並べる」という2つの機械的な手順に集約されます。 頻出する値(FF=255など)を覚えておくと暗算の速度が上がりますが、大きな数値や検算には Number Base Converter を使うのが確実です。

Hex-to-decimal conversion is place-value multiplication by powers of 16; decimal-to-hex is repeated division by 16 with remainders read bottom-up. Memorizing common values like FF = 255 speeds up mental math, but for large numbers or verification, use a BigInt-safe converter rather than a language's native 32-bit integer parser.

Number Base Converter

2/8/10/16進数を入力するだけで残り3つを同時表示。桁数の大きい数値もBigIntで正確に変換します。

今すぐ試す →

よくある質問 / FAQ

16進数を10進数に変換する式は?
各桁の値に16の累乗を掛けて合計します。例えば1Aなら 1×16^1 + 10×16^0 = 16 + 10 = 26 です。Aは10、Bは11…Fは15を表す1桁の記号として扱います。
10進数を16進数に変換するには?
16で割り続け、商が0になるまでの余りを逆順に並べます。200を例にすると 200÷16=12 余り8、12÷16=0 余り12(C)なので、逆順に読んでC8になります。
0xという表記は何を意味する?
0xはその数値が16進数であることを示すプレフィックスで、C言語系の言語(JavaScript, Python, Java, Cなど)で広く使われる慣習です。0x1A は10進数の26と同じ値です。プレフィックスなしでhexだけを扱うツールも多いため、貼り付け時は0xの有無に注意してください。
How do I convert to hexadecimal from a negative decimal number?
Most languages represent negative integers in a fixed bit width using two's complement, so the hex form depends on the integer size (8/16/32/64-bit). For example, -1 as a signed 8-bit integer is 0xFF, but as 32-bit it is 0xFFFFFFFF. Always confirm the bit width before comparing hex output across languages.
Why does parseInt('08', 16) not equal 8?
It does — parseInt with an explicit radix of 16 reads '08' as hex digits 0 and 8, giving decimal 8. The classic bug is omitting the radix: parseInt('08') without a radix can be misread as octal in older engines. Always pass the radix explicitly.

関連ツール / Related tools

関連ガイド / Related guides