Binary ماشینحساب
از Binary ماشینحساب برای دریافت نتایج سریع و دقیق استفاده کنید.
نحوه استفاده از این ماشین حساب
- Binary Number A را وارد کنید
- Binary Number B را وارد کنید
- روی دکمه محاسبه کلیک کنید
- نتیجه نمایش داده شده در زیر ماشین حساب را بخوانید
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:
| Position | 2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
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:
- 181 ÷ 2 = 90 remainder 1
- 90 ÷ 2 = 45 remainder 0
- 45 ÷ 2 = 22 remainder 1
- 22 ÷ 2 = 11 remainder 0
- 11 ÷ 2 = 5 remainder 1
- 5 ÷ 2 = 2 remainder 1
- 2 ÷ 2 = 1 remainder 0
- 1 ÷ 2 = 0 remainder 1
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:
| Unit | Size | Maximum Value (unsigned) | Common Use |
|---|---|---|---|
| Bit | 1 binary digit | 1 | Boolean flag, single binary value |
| Nibble | 4 bits | 15 (hex: F) | One hexadecimal digit |
| Byte | 8 bits | 255 | Single character (ASCII), color channel |
| Word | 16 bits | 65,535 | Legacy 16-bit systems, Unicode basic |
| Double Word (DWORD) | 32 bits | 4,294,967,295 | 32-bit integers, IPv4 addresses |
| Quad Word (QWORD) | 64 bits | 18,446,744,073,709,551,615 | Modern 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.
| Operation | Symbol | Behavior | Example |
|---|---|---|---|
| AND | & | 1 if BOTH bits are 1 | 1010 & 1100 = 1000 |
| OR | | | 1 if EITHER bit is 1 | 1010 | 1100 = 1110 |
| XOR | ^ | 1 if bits are DIFFERENT | 1010 ^ 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:
- Bit masking: Check if a specific bit is set:
if (flags & 0b0100) { ... }— checks if bit 2 is 1. - Setting a bit:
flags = flags | 0b0100— sets bit 2 to 1 regardless of current value. - Clearing a bit:
flags = flags & ~0b0100— clears bit 2 to 0. - Fast multiplication/division by powers of 2:
n << 3= n × 8;n >> 2= n ÷ 4. Bit shifts are CPU-level operations, significantly faster than multiplication. - Checking even/odd:
if (n & 1) { /* odd */ }— the last bit of any odd number is always 1.
Number Systems Comparison: Binary, Octal, Decimal, Hexadecimal
Computer science uses four number systems, each suited to different contexts:
| System | Base | Digits | Common Use |
|---|---|---|---|
| Binary (base-2) | 2 | 0, 1 | CPU operations, storage, logic |
| Octal (base-8) | 8 | 0–7 | Unix file permissions, older systems |
| Decimal (base-10) | 10 | 0–9 | Human-readable numbers |
| Hexadecimal (base-16) | 16 | 0–9, A–F | Memory addresses, color codes, machine code |
Quick conversion: binary ↔ hex (4 binary digits = 1 hex digit):
| Binary | Hex | Decimal | Binary | Hex | Decimal |
|---|---|---|---|---|---|
| 0000 | 0 | 0 | 1000 | 8 | 8 |
| 0001 | 1 | 1 | 1001 | 9 | 9 |
| 0010 | 2 | 2 | 1010 | A | 10 |
| 0011 | 3 | 3 | 1011 | B | 11 |
| 0100 | 4 | 4 | 1100 | C | 12 |
| 0101 | 5 | 5 | 1101 | D | 13 |
| 0110 | 6 | 6 | 1110 | E | 14 |
| 0111 | 7 | 7 | 1111 | F | 15 |
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.
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.
آخرین بهروزرسانی: March 2026