What Is Number Base Conversion
Number base conversion is the process of translating values between different numeral systems. The most commonly used bases in computer science are:
| Base | Radix | Digits | Common Usage |
|------|-------|--------|-------------|
| Binary | 2 | 0, 1 | Computer internals, bitwise operations |
| Octal | 8 | 0-7 | Unix file permissions (chmod 755) |
| Decimal | 10 | 0-9 | Everyday human counting |
| Hexadecimal | 16 | 0-9, A-F | Memory addresses, color codes, hashes |
Why You Need Base Conversion
- Low-level debugging: Memory addresses and byte data require hexadecimal
- Bitwise operations: Bitmasks and shifts need binary thinking
- Color handling: CSS colors use hex (
#FF5733) - Network configuration: Subnet masks involve binary-decimal conversion
- File permissions: Linux permissions use octal (
chmod 755) - Encoding debugging: Base64 and URL encoding involve hex at the low level
Base Conversion Methods
Manual Conversion Techniques
Decimal → Binary (divide by 2, collect remainders):
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Result: 1101
Decimal → Hexadecimal (divide by 16, collect remainders):
255 ÷ 16 = 15 remainder 15 (F)
15 ÷ 16 = 0 remainder 15 (F)
Result: FF
Programming Language Conversion
JavaScript / TypeScript:
const num = 255;
num.toString(2) // "11111111" (binary)
num.toString(8) // "377" (octal)
num.toString(10) // "255" (decimal)
num.toString(16) // "ff" (hex)
// String → Number
parseInt("ff", 16) // 255
parseInt("11111111", 2) // 255
Python:
num = 255
bin(num) # "0b11111111"
oct(num) # "0o377"
hex(num) # "0xff"
# String → Number
int("ff", 16) # 255
int("11111111", 2) # 255
Go:
import "strconv"
num := 255
strconv.FormatInt(int64(num), 2) // "11111111"
strconv.FormatInt(int64(num), 8) // "377"
strconv.FormatInt(int64(num), 16) // "ff"
// String → Number
strconv.ParseInt("ff", 16, 64) // 255
strconv.ParseInt("11111111", 2, 64) // 255
How to Use an Online Number Base Converter
Using DevToolkit Pro's Number Base Converter:
- Enter a value in any base
- Select the input base (2/8/10/16)
- See all base conversions instantly
- One-click copy for any format
Quick Reference Table
| Decimal | Binary | Octal | Hexadecimal | |---------|--------|-------|-------------| | 0 | 0000 | 0 | 0 | | 1 | 0001 | 1 | 1 | | 8 | 1000 | 10 | 8 | | 10 | 1010 | 12 | A | | 16 | 10000 | 20 | 10 | | 64 | 1000000 | 100 | 40 | | 128 | 10000000 | 200 | 80 | | 255 | 11111111 | 377 | FF |
FAQ
Why Do Programmers Prefer Hexadecimal?
Hex is a human-friendly shorthand for binary. 1 hex digit = 4 binary digits, so 0xFF directly maps to 11111111. Hex is more intuitive than decimal when representing bytes and memory addresses.
Is Octal Still Relevant?
Primarily for Linux file permissions. chmod 755 uses octal: 7=rwx, 5=r-x. Also used for escape sequences in some languages (\012 = newline).
How to Quickly Convert Binary to Hex?
Every 4 binary digits map to 1 hex digit. Group right-to-left: 1111 1111 → F F → FF. This is a direct mapping in computer hardware.
This article is brought to you by DevToolkit Pro. More developer tools at the homepage.
相关文章
Online Word Counter: Count Words, Characters, Lines Instantly
Learn how to use an online word counter to count words, characters, lines, and paragraphs. Understand Chinese vs English counting differences and use cases in writing and development.
UUID Generator: Complete Guide to Unique Identifiers (UUID, NanoID, ULID)
Understand UUID v4, NanoID, and ULID fundamentals. Learn how to use an online UUID generator, and discover best practices for databases, distributed systems, and API tracking.
Online User-Agent Parser: Identify Browser and Device Information
Learn how to parse User-Agent strings. Understand browser, operating system, and device type identification methods, and applications in data analytics and compatibility testing.