Number Base Converter
Convert numbers between binary, octal, decimal, and hexadecimal.
Number Base Converter translates integer values between the four numeral systems most commonly encountered in computing: decimal (base 10), binary (base 2), octal (base 8), and hexadecimal (base 16). Each system represents the same value using a different set of digits and is preferred in specific contexts β binary in hardware, hex in memory addresses and color codes, and decimal in everyday arithmetic.
Enter a number in any of the four fields and the tool instantly fills in the other three. The binary output groups digits in nibbles (4 bits) for readability, and the hexadecimal output is displayed in uppercase. You can also convert negative numbers using two's complement for signed representation.
Understanding base conversion is fundamental for reading RGB color codes, interpreting Unix file permissions, working with bitwise operations, and reading memory dumps or disassembled code. This tool handles the arithmetic instantly so you can focus on the logic.
Frequently Asked Questions
Code Implementation
# 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.