1. Foundations of Computing

Binary Systems

Study of binary number representation, conversions between binary, decimal and hexadecimal, and basic bitwise concepts.

Binary Systems

Hey students! šŸ‘‹ Welcome to one of the most fundamental concepts in computer science - binary systems! In this lesson, you'll discover how computers actually "think" and process information using just two digits: 0 and 1. By the end of this lesson, you'll understand how to convert between binary, decimal, and hexadecimal number systems, and grasp the basic concepts of bitwise operations. Think of this as learning the secret language that every computer, smartphone, and digital device uses to communicate! šŸ–„ļø

Understanding Binary: The Language of Computers

Binary is a base-2 number system that uses only two digits: 0 and 1. Unlike our familiar decimal system (base-10) that uses digits 0-9, binary represents all numbers using combinations of just these two symbols. But why do computers use binary? šŸ¤”

The answer lies in how computers are built! Inside your computer, millions of tiny switches called transistors can only be in two states: ON (representing 1) or OFF (representing 0). This makes binary the perfect match for computer hardware. Each binary digit is called a bit (short for binary digit), and 8 bits together make a byte.

Let's look at how binary place values work. In decimal, each position represents a power of 10 (1, 10, 100, 1000...). In binary, each position represents a power of 2:

$$2^7, 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^0$$

Which equals: 128, 64, 32, 16, 8, 4, 2, 1

For example, the binary number 10110011 breaks down like this:

  • Position 7 (128): 1 Ɨ 128 = 128
  • Position 6 (64): 0 Ɨ 64 = 0
  • Position 5 (32): 1 Ɨ 32 = 32
  • Position 4 (16): 1 Ɨ 16 = 16
  • Position 3 (8): 0 Ɨ 8 = 0
  • Position 2 (4): 0 Ɨ 4 = 0
  • Position 1 (2): 1 Ɨ 2 = 2
  • Position 0 (1): 1 Ɨ 1 = 1

Total: 128 + 32 + 16 + 2 + 1 = 179 in decimal! šŸŽÆ

Converting Between Binary and Decimal

Converting from binary to decimal is straightforward - just add up the place values where you see a 1, as we did above. But what about going the other way?

Converting Decimal to Binary uses a simple division method:

Let's convert the decimal number 27 to binary:

  1. 27 Ć· 2 = 13 remainder 1
  2. 13 Ć· 2 = 6 remainder 1
  3. 6 Ć· 2 = 3 remainder 0
  4. 3 Ć· 2 = 1 remainder 1
  5. 1 Ć· 2 = 0 remainder 1

Reading the remainders from bottom to top: 11011

Let's verify: $1Ɨ2^4 + 1Ɨ2^3 + 0Ɨ2^2 + 1Ɨ2^1 + 1Ɨ2^0 = 16 + 8 + 0 + 2 + 1 = 27$ āœ…

Another method is subtraction: Start with the largest power of 2 that fits into your number, subtract it, place a 1 in that position, then repeat with the remainder.

For 27:

  • 27 - 16 = 11 (place 1 in $2^4$ position)
  • 11 - 8 = 3 (place 1 in $2^3$ position)
  • 3 - 4? No, so place 0 in $2^2$ position
  • 3 - 2 = 1 (place 1 in $2^1$ position)
  • 1 - 1 = 0 (place 1 in $2^0$ position)

Result: 11011 šŸŽ‰

Hexadecimal: The Programmer's Shortcut

Hexadecimal (hex) is a base-16 system using digits 0-9 and letters A-F, where A=10, B=11, C=12, D=13, E=14, F=15. Why is hex so popular in computing? Because it's incredibly convenient for representing binary numbers!

Here's the magic: 4 binary digits = 1 hex digit exactly! This makes conversions super easy.

Binary to Hex Conversion:

Take the binary number 10110011:

  1. Split into groups of 4 from right: 1011 0011
  2. Convert each group:
  • 1011 = 8+2+1 = 11 = B in hex
  • 0011 = 2+1 = 3 = 3 in hex
  1. Result: B3 in hexadecimal

Hex to Binary: Just reverse the process! F4 in hex becomes:

  • F = 15 = 1111 in binary
  • 4 = 4 = 0100 in binary
  • Result: 11110100

Decimal to Hex uses repeated division by 16:

Convert 255 to hex:

  1. 255 Ć· 16 = 15 remainder 15 (F)
  2. 15 Ć· 16 = 0 remainder 15 (F)

Result: FF (which makes sense - 255 is the maximum value for 8 bits!) šŸ’”

Basic Bitwise Operations

Bitwise operations work directly on individual bits and are fundamental to computer processing. Let's explore the main ones:

AND Operation (&): Returns 1 only when both bits are 1

  1010
& 1100
------
  1000

OR Operation (|): Returns 1 when at least one bit is 1

  1010
| 1100  
------
  1110

XOR Operation (^): Returns 1 when bits are different

  1010
^ 1100
------
  0110

NOT Operation (~): Flips all bits (1 becomes 0, 0 becomes 1)

~ 1010
------
  0101

These operations are incredibly fast and are used in everything from graphics processing to encryption algorithms! For example, XOR is used in simple encryption - if you XOR a message with a key, then XOR the result with the same key, you get back the original message! šŸ”

Bit Shifting is another important concept:

  • Left shift (<<): Moves bits left, filling with zeros (effectively multiplies by 2)
  • Right shift (>>): Moves bits right (effectively divides by 2)

Example: 1010 << 1 = 10100 (10 becomes 20 in decimal)

Conclusion

students, you've just mastered the fundamental language of computers! Binary systems form the foundation of all digital technology, from the smartphone in your pocket to the most powerful supercomputers. You now understand how to convert between binary, decimal, and hexadecimal number systems, and you've learned about basic bitwise operations that computers use millions of times per second. These concepts aren't just academic - they're the building blocks that make our digital world possible! 🌟

Study Notes

• Binary is a base-2 system using only digits 0 and 1

• Each binary position represents a power of 2: $2^0, 2^1, 2^2, 2^3...$ (1, 2, 4, 8...)

• Bit = one binary digit, Byte = 8 bits

• Binary to Decimal: Add up place values where there's a 1

• Decimal to Binary: Repeatedly divide by 2, read remainders bottom-to-top

• Hexadecimal uses base-16 with digits 0-9 and A-F (A=10, B=11, C=12, D=13, E=14, F=15)

• 4 binary digits = 1 hex digit exactly

• Binary to Hex: Group binary digits in 4s, convert each group

• Bitwise AND (&): Returns 1 only when both bits are 1

• Bitwise OR (|): Returns 1 when at least one bit is 1

• Bitwise XOR (^): Returns 1 when bits are different

• Bitwise NOT (~): Flips all bits

• Left shift (<<): Multiplies by 2, Right shift (>>): Divides by 2

Practice Quiz

5 questions to test your understanding

Binary Systems — GCSE Computer Science | A-Warded