Number Base Converter
2進数、8進数、10進数、16進数間で数値を変換。
10進数(Base 10)
2進数(Base 2)
8進数(Base 8)
16進数(Base 16)
進数変換ツールは、コンピューティングで最もよく使われる4つの数値システム間で整数値を変換します:10進数(base 10)、2進数(base 2)、8進数(base 8)、16進数(base 16)。各システムは異なる数字セットを使用して同じ値を表し、特定のコンテキストで使用されます — ハードウェアでは2進数、メモリアドレスと色コードでは16進数、日常の計算では10進数。
4つのフィールドのいずれかに数値を入力すると、ツールは即座に他の3つを埋めます。2進数の出力は読みやすさのためにニブル(4ビット)でグループ化され、16進数の出力は大文字で表示されます。
進数変換の理解はRGBカラーコードの読み取り、Unixファイル権限の解釈、ビット演算の操作、メモリダンプや逆アセンブルされたコードの読み取りに不可欠です。
よくある質問
コード実装
# Python: built-in base conversion
# Decimal → other bases
n = 255
print(bin(n)) # '0b11111111' (binary)
print(oct(n)) # '0o377' (octal)
print(hex(n)) # '0xff' (hex)
# Other bases → decimal using int(string, base)
print(int("ff", 16)) # 255 (hex → decimal)
print(int("11111111", 2)) # 255 (binary → decimal)
print(int("377", 8)) # 255 (octal → decimal)
# Arbitrary base → decimal (base 36 example)
print(int("z", 36)) # 35
# Decimal → arbitrary base string
def to_base(n: int, base: int) -> str:
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if n == 0:
return "0"
result = []
while n:
result.append(digits[n % base])
n //= base
return "".join(reversed(result))
print(to_base(255, 16)) # FF
print(to_base(255, 2)) # 11111111Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.