DevToolBox

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

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

まとめ / 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で正確に変換します。

今すぐ試す →

関連ツール / Related tools

関連ガイド / Related guides