Binary Calculator
Convert between binary, decimal, hexadecimal and octal. Add and subtract binary numbers with full carry workings. Perform AND, OR, XOR and NOT bitwise operations. Essential for GCSE Computer Science and programming.
Conversion Reference Table (0–15)
| Decimal | Binary | Hex | Octal |
|---|
What Is Binary? The Base-2 Number System
Binary is a base-2 number system that uses only two digits: 0 and 1. Every number you can write in decimal (base 10) can also be written in binary — just using a different set of symbols. The word bit comes from binary digit.
Computers use binary because electronic components can reliably represent two states: a transistor is either off (0) or on (1). Building reliable circuits for ten distinct states (as decimal would require) is far more complex. By working in binary, engineers can design circuits that are fast, cheap and reliable.
How Place Values Work in Binary
Just as decimal uses powers of 10 (ones, tens, hundreds, thousands…), binary uses powers of 2:
| Position (from right) | Power of 2 | Value |
|---|---|---|
| 1st (units) | 20 | 1 |
| 2nd | 21 | 2 |
| 3rd | 22 | 4 |
| 4th | 23 | 8 |
| 5th | 24 | 16 |
| 6th | 25 | 32 |
| 7th | 26 | 64 |
| 8th | 27 | 128 |
To convert binary to decimal, multiply each digit by its place value and add the results. For example: 1011 = 1×8 + 0×4 + 1×2 + 1×1 = 8 + 0 + 2 + 1 = 11.
Converting Decimal to Binary (Division Method)
Divide the decimal number by 2 repeatedly and record the remainders. Then read the remainders from bottom to top.
Example: Convert 13 to binary
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Reading remainders upward: 1310 = 11012
Binary Addition with Carries
Binary addition uses four simple rules:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (write 0, carry 1)
- 1 + 1 + 1 = 11 (write 1, carry 1)
These rules mirror decimal addition but with only two values. The carry propagates leftward exactly as in decimal arithmetic.
Two's Complement: Negative Numbers in Binary
Computers represent negative numbers using two's complement. To find the two's complement of a binary number:
- Write the number in binary (using enough bits, e.g. 8).
- Flip all the bits (change 0 to 1 and 1 to 0) — this is the one's complement.
- Add 1 to the result.
For example, to represent −5 in 8-bit binary: +5 = 00000101 → flip: 11111010 → add 1: 11111011. This method makes subtraction equivalent to adding the negative number, simplifying CPU design enormously.
Hexadecimal and Its Relationship to Binary
Hexadecimal (hex, base 16) is used extensively in computing because it provides a compact representation of binary data. Each hex digit represents exactly 4 binary bits (called a nibble). The hex digits are 0–9 and A–F:
| Decimal | Binary (4-bit) | Hex |
|---|---|---|
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
To convert binary to hex: group bits in fours from the right, then replace each group with its hex digit. For example: 11110101 = 1111 0101 = F516.
Bits, Bytes and Storage Sizes
Understanding the hierarchy of data storage units is essential for computer science:
| Unit | Size | Values Possible |
|---|---|---|
| 1 bit | 1 binary digit | 2 (0 or 1) |
| 4 bits (nibble) | 1 hex digit | 16 |
| 8 bits (byte) | 2 hex digits | 256 (0–255) |
| 1 kilobyte (KB) | 1,024 bytes | 8,192 bits |
| 1 megabyte (MB) | 1,024 KB | ~8.4 million bits |
| 1 gigabyte (GB) | 1,024 MB | ~8.6 billion bits |
| 1 terabyte (TB) | 1,024 GB | ~8.8 trillion bits |
Bitwise Operations in Programming
Bitwise operations compare binary numbers bit by bit. They are used extensively in programming for flags, masks, permissions, encryption and graphics:
- AND (&): Result bit is 1 only if both input bits are 1. Example: 1010 AND 1100 = 1000.
- OR (|): Result bit is 1 if either input bit is 1. Example: 1010 OR 1100 = 1110.
- XOR (^): Result bit is 1 if the bits are different. Example: 1010 XOR 1100 = 0110. XOR is used in checksums and simple encryption.
- NOT (~): Flips all bits. Example: NOT 1010 = 0101 (in 4-bit).
ASCII and Binary: How Text Becomes Numbers
Text characters are stored in computers as numbers, then those numbers are stored as binary. The ASCII (American Standard Code for Information Interchange) standard assigns a number to each character. For example: the letter A = 6510 = 010000012. A space = 3210 = 001000002. Modern systems use Unicode (UTF-8), which extends ASCII to cover all world languages, emojis and special symbols.
Binary in GCSE Computer Science
Binary, hexadecimal and number systems are a core topic in GCSE Computer Science (AQA, OCR, Eduqas, WJEC). Key skills include:
- Converting between binary, decimal and hexadecimal
- Binary addition and the role of overflow
- Two's complement for negative numbers
- Logical shifts (left shift = multiply by 2; right shift = divide by 2)
- Bitwise AND, OR and NOT
- Understanding storage units: bit, nibble, byte, KB, MB, GB, TB