Skip to main content
🔬 Advanced

เครื่องคิดเลขฐานสอง – Binary Calculator

Perform binary addition, subtraction, multiplication, and division. Convert between binary and decimal.

วิธีใช้เครื่องคิดเลขนี้

  1. ป้อนBinary Number A
  2. ป้อนBinary Number B
  3. คลิกปุ่มคำนวณ
  4. อ่านผลลัพธ์ที่แสดงด้านล่างเครื่องคิดเลข

The Binary Number System: How Computers Count

The binary number system (base-2) uses only two digits — 0 and 1 — called bits (binary digits). Every computer, smartphone, and digital device internally stores and processes all information in binary, because electrical circuits can reliably represent two distinct states: high voltage (1) and low voltage (0).

Each position in a binary number represents a power of 2, increasing from right to left:

Position2⁷2⁶2⁵2⁴2⁰
Value1286432168421

Binary to decimal conversion: Multiply each bit by its place value and sum all results.

Example: 10110101₂ = 1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 1×4 + 0×2 + 1×1 = 128 + 32 + 16 + 4 + 1 = 181

Decimal to binary conversion: Repeatedly divide by 2, recording the remainder at each step, then read remainders from bottom to top.

Example: Convert 181 to binary:

Read remainders bottom to top: 10110101₂

Binary Arithmetic: Addition, Subtraction, and Multiplication

Binary arithmetic follows the same rules as decimal, but carries happen at 2 instead of 10.

Binary addition rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1), 1+1+1=11 (carry 1)

Example: 1011₂ + 1101₂ (11 + 13 = 24)

  1011
+ 1101
------
 11000

Working right to left: 1+1=10 (write 0, carry 1); 1+0+1=10 (write 0, carry 1); 0+1+1=10 (write 0, carry 1); 1+1+1=11 (write 1, carry 1); final carry writes 1. Result: 11000₂ = 24 ✓

Two's complement (binary subtraction): Computers handle negative numbers and subtraction using two's complement representation. To find the two's complement of a number: flip all bits, then add 1.

Example: −13 in 8-bit two's complement: +13 = 00001101₂ → flip all bits → 11110010₂ → add 1 → 11110011₂

This allows subtraction to be performed as addition: 20 − 13 = 20 + (−13).

Binary multiplication is elegant: each partial product is either 0 (multiplying by 0) or the number itself (multiplying by 1), shifted left. Example: 1011₂ × 101₂ (11 × 5 = 55):

    1011
  ×  101
  -----
    1011    (1011 × 1)
   0000     (1011 × 0, shifted)
  1011      (1011 × 1, shifted twice)
  -------
  110111₂ = 55 ✓

Binary in Computing: Bits, Bytes, and Data Sizes

Understanding binary units is essential for anyone working with computers, storage, or network speeds:

UnitSizeMaximum Value (unsigned)Common Use
Bit1 binary digit1Boolean flag, single binary value
Nibble4 bits15 (hex: F)One hexadecimal digit
Byte8 bits255Single character (ASCII), color channel
Word16 bits65,535Legacy 16-bit systems, Unicode basic
Double Word (DWORD)32 bits4,294,967,29532-bit integers, IPv4 addresses
Quad Word (QWORD)64 bits18,446,744,073,709,551,615Modern integers, pointers, timestamps

Color values: Web colors use 24-bit RGB (8 bits per channel). #FF5733 = R:255, G:87, B:51. Each 8-bit channel can represent 256 shades (0–255). Total possible colors: 256³ = 16,777,216 (about 16.7 million).

File permissions in Unix/Linux: rwxr-xr-- = 111 101 100 in binary = 7, 5, 4 in octal = chmod 754. Each set of 3 bits represents read (r=4), write (w=2), and execute (x=1) permissions for owner, group, and others.

Bitwise Operations and Their Applications

Bitwise operations manipulate individual bits within integers. They are fundamental to low-level programming, cryptography, network programming, and performance-critical code.

OperationSymbolBehaviorExample
AND&1 if BOTH bits are 11010 & 1100 = 1000
OR|1 if EITHER bit is 11010 | 1100 = 1110
XOR^1 if bits are DIFFERENT1010 ^ 1100 = 0110
NOT~Flip all bits~1010 = 0101
Left Shift<<Shift bits left (×2 each shift)1011 << 1 = 10110 (×2)
Right Shift>>Shift bits right (÷2 each shift)1011 >> 1 = 0101 (÷2)

Practical uses:

Number Systems Comparison: Binary, Octal, Decimal, Hexadecimal

Computer science uses four number systems, each suited to different contexts:

SystemBaseDigitsCommon Use
Binary (base-2)20, 1CPU operations, storage, logic
Octal (base-8)80–7Unix file permissions, older systems
Decimal (base-10)100–9Human-readable numbers
Hexadecimal (base-16)160–9, A–FMemory addresses, color codes, machine code

Quick conversion: binary ↔ hex (4 binary digits = 1 hex digit):

BinaryHexDecimalBinaryHexDecimal
000000100088
000111100199
0010221010A10
0011331011B11
0100441100C12
0101551101D13
0110661110E14
0111771111F15

This 4-bit grouping makes hex extremely useful as a compact notation for binary data: the 32-bit value 11001010 00111111 10110101 00001100 is much easier to write as CA3FB50C.

อัปเดตล่าสุด: March 2026

Frequently Asked Questions

Why do computers use binary instead of decimal?

Electronic circuits are most reliable with just two distinct states: on (high voltage ≈ 1) and off (low voltage ≈ 0). Representing 10 distinct states for decimal would require much more precise voltage control and would be far more susceptible to electrical noise. Binary's simplicity allows billions of transistors to operate reliably at GHz speeds with billions of operations per second.

What is the largest number a byte can hold?

A byte (8 bits) can represent 2⁸ = 256 different values. For unsigned integers: 0 to 255. For signed integers (two's complement): −128 to 127. The maximum unsigned byte value in binary is 11111111₂ = 255; in hex it's FF.

How do I convert a negative number to binary?

Use two's complement: (1) Convert the positive version to binary, (2) Flip all bits (0→1, 1→0), (3) Add 1. Example — −13 in 8-bit: +13 = 00001101₂, flip bits = 11110010₂, add 1 = 11110011₂. This is how all modern computers store negative integers.

What is the difference between binary and hexadecimal?

Both are positional number systems used in computing. Binary (base-2) uses only 0 and 1 — the native language of computers. Hexadecimal (base-16) uses 0–9 and A–F as a compact notation for binary — every 4 binary digits correspond to exactly 1 hex digit. Hex is used for memory addresses, color codes (#RRGGBB), and machine code because it's more compact and readable than raw binary.

What are bitwise operations used for?

Bitwise operations (AND, OR, XOR, NOT, shifts) manipulate individual bits within integers. Common uses: bit flags and permissions (Unix chmod), checking even/odd (n & 1), fast multiplication/division by powers of 2 (bit shifting), encryption algorithms, hash functions, CRC error detection, network subnet masks, and game development (compact state storage in a single integer).

What is binary floating point and why does 0.1 + 0.2 ≠ 0.3 in programming?

Most modern computers use IEEE 754 binary floating point, which represents decimal fractions in binary. Just as 1/3 = 0.3333... cannot be represented exactly in decimal, 1/10 cannot be represented exactly in binary (it's an infinitely repeating binary fraction). This causes tiny rounding errors: in most languages, 0.1 + 0.2 = 0.30000000000000004. Use integer arithmetic (work in cents, not dollars) or decimal libraries for exact financial calculations.

How is binary used in data storage and file sizes?

Storage is measured in bytes (8 bits), kilobytes (1,024 bytes), megabytes (1,024 KB), gigabytes (1,024 MB), etc. Note: hard drive manufacturers use SI prefixes (1 KB = 1,000 bytes) while operating systems use binary prefixes (1 KiB = 1,024 bytes), causing the apparent "missing space" discrepancy when you buy storage. A 1 TB drive shows ~931 GiB in Windows because 1,000,000,000,000 ÷ 1,073,741,824 ≈ 931.

What is binary-coded decimal (BCD)?

BCD encodes each decimal digit as a 4-bit binary group: 0=0000, 1=0001, ..., 9=1001. So decimal 93 in BCD is 1001 0011. BCD is used in financial systems (avoids floating-point rounding errors), digital clocks and displays (7-segment displays decode BCD directly), and old mainframe systems. It's less space-efficient than pure binary but eliminates decimal-to-binary conversion errors in critical applications.