How Computers Store and Manipulate Data: From Binary to ASCII

CSEC ICT Essential Knowledge: Computers process and store all information using binary digits (bits) – the fundamental language of computing. Understanding number systems (binary, octal, hexadecimal), binary arithmetic, integer representations, and character encoding (ASCII) is essential for understanding how computers work at their most basic level.

Key Concept: All digital data – whether numbers, text, images, or sound – is ultimately represented and manipulated as sequences of 0s and 1s. Different encoding schemes translate between human-readable information and computer-processable binary data.

Part 1: Number Systems in Computing

๐Ÿ”ข

The Binary System: Foundation of Computing

01
Why Binary?

Computers use binary because electronic components can reliably represent two states: ON/OFF, HIGH/LOW voltage, or magnetized/not magnetized. These two states are represented as 1 and 0.

1
0
1
0
1
1
0
0

A byte (8 bits) representing the binary number 10101100

๐Ÿ“Š
Binary Place Values

Binary is a base-2 system. Each digit (bit) represents a power of 2, starting from 2โฐ at the rightmost position.

1
2ยณ = 8
0
2ยฒ = 4
1
2ยน = 2
1
2โฐ = 1

Binary 1011 = (1ร—8) + (0ร—4) + (1ร—2) + (1ร—1) = 8 + 0 + 2 + 1 = 11 in decimal

Binary (Base-2)

Digits: 0, 1

Example: 1101โ‚‚ = 13โ‚โ‚€

Conversion: Sum of powers of 2

Use: Direct computer processing

1101โ‚‚ = 1ร—8 + 1ร—4 + 0ร—2 + 1ร—1 = 13

Octal (Base-8)

Digits: 0-7

Example: 75โ‚ˆ = 61โ‚โ‚€

Conversion: Sum of powers of 8

Use: Shortening binary (3 bits = 1 octal digit)

75โ‚ˆ = 7ร—8 + 5ร—1 = 56 + 5 = 61

Hexadecimal (Base-16)

Digits: 0-9, A-F

Example: 2Fโ‚โ‚† = 47โ‚โ‚€

Conversion: Sum of powers of 16

Use: Shortening binary (4 bits = 1 hex digit), memory addresses

2Fโ‚โ‚† = 2ร—16 + 15ร—1 = 32 + 15 = 47
๐Ÿ”„

Converting Between Number Systems

โ†”๏ธ
Binary โ†” Decimal

Binary to Decimal: Sum the powers of 2 for each ‘1’ bit

Decimal to Binary: Repeated division by 2, collecting remainders

Binary
10110โ‚‚
โ†’
Calculation
(1ร—16)+(0ร—8)+(1ร—4)+(1ร—2)+(0ร—1)
โ†’
Decimal
22โ‚โ‚€
๐Ÿ”„
Binary โ†” Hexadecimal

Group binary digits into sets of 4 (from right), convert each group to hex

Example Conversion

Binary: 1101 0110

Group 1: 1101 = Dโ‚โ‚† (13 in decimal)

Group 2: 0110 = 6โ‚โ‚†

Result: D6โ‚โ‚†

Memory Aid: For hex digits A-F: A=10, B=11, C=12, D=13, E=14, F=15. Remember “All Boys Can Develop Excellent Focus” or create your own mnemonic!

Part 2: Binary Arithmetic

โž•

Binary Addition and Subtraction

โž•
Binary Addition Rules

Follows simple rules similar to decimal addition but with only two digits:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 0, carry 1
  • 1 + 1 + 1 = 1, carry 1

Example: 0110 + 0101 (6 + 5 in decimal)

Carry:     1  1   
       0 1 1 0
+      0 1 0 1
       1 0 1 1

Result: 1011โ‚‚ = 11โ‚โ‚€ (6 + 5 = 11 โœ“)

โž–
Binary Subtraction Methods

Two primary methods:

  1. Direct Subtraction: Similar to decimal borrowing
  2. Using Two’s Complement: More efficient for computers (see below)
Direct Subtraction Example

1010 – 0110 (10 – 6 in decimal)

Step 1: 0 – 0 = 0

Step 2: Borrow needed: 1 – 1 = 0 (after borrowing)

Step 3: 0 – 1 = 1 (with borrow)

Step 4: 0 – 0 = 0

Result: 0100โ‚‚ = 4โ‚โ‚€ (10 – 6 = 4 โœ“)

Part 3: Integer Representation in Computers

โ„น๏ธ

Representing Positive and Negative Integers

Sign and Magnitude

Concept: Leftmost bit indicates sign (0=positive, 1=negative), remaining bits show magnitude

Example (8-bit): +5 = 00000101, -5 = 10000101

Advantage: Simple to understand

Disadvantage: Two representations of zero (+0 and -0), complex arithmetic

Binary Coded Decimal (BCD)

Concept: Each decimal digit represented by 4 binary bits

Example: 47 = 0100 0111 (4=0100, 7=0111)

Advantage: Accurate decimal representation

Disadvantage: Inefficient storage, complex arithmetic

Two’s Complement

Concept: Most significant bit indicates sign, negative numbers represented as complement+1

Example (8-bit): +5 = 00000101, -5 = 11111011

Advantage: Single zero representation, simple subtraction via addition

Disadvantage: Range asymmetry (one extra negative number)

๐ŸŽฏ
Two’s Complement in Detail

This is the standard method used by modern computers because it simplifies arithmetic operations.

Creating Two’s Complement (8-bit example):

1. Start with positive number: +5 = 00000101

2. Invert all bits (1’s complement): 11111010

3. Add 1: 11111010 + 1 = 11111011

Result: -5 = 11111011

Range for 8-bit: -128 to +127 (Note: one extra negative number)

Why Two’s Complement? Subtraction becomes addition! To calculate A – B, the computer finds two’s complement of B and adds it to A. This simplifies hardware design as only addition circuits are needed.

Part 4: Character Representation – ASCII

๐Ÿ”ค

ASCII: The Universal Text Code

๐Ÿ“–
What is ASCII?

ASCII (American Standard Code for Information Interchange) is a 7-bit character encoding standard that represents text in computers. Originally 128 characters, extended ASCII uses 8 bits (256 characters).

Sample ASCII Characters:
NUL SOH STX ETX A B C 1 2 3 ! @ #

Control characters (red) and printable characters (green)

๐Ÿ”ข
ASCII Code Structure
  • 0-31: Control characters (non-printable)
  • 32-126: Printable characters (letters, digits, punctuation)
  • 127: Delete character
  • 128-255: Extended ASCII (varies by system)
Character ASCII Code (Decimal) Binary (7-bit) Hex
‘A’ (uppercase) 65 100 0001 41
‘a’ (lowercase) 97 110 0001 61
‘0’ (zero) 48 011 0000 30
Space 32 010 0000 20
New Line 10 000 1010 0A
๐ŸŒ
Beyond ASCII: Unicode

ASCII’s limitation (only 128/256 characters) led to Unicode, which can represent over 1 million characters covering all writing systems.

  • UTF-8: Variable length (1-4 bytes), backward compatible with ASCII
  • UTF-16: 2 or 4 bytes per character
  • UTF-32: Fixed 4 bytes per character

Most modern systems use UTF-8 as it’s efficient for English text while supporting all languages.

Quiz: Test Your Understanding

Data Representation Quiz
Question 1: Convert the binary number 11001101 to decimal and hexadecimal.
Answer:
To Decimal:
11001101โ‚‚ = (1ร—128) + (1ร—64) + (0ร—32) + (0ร—16) + (1ร—8) + (1ร—4) + (0ร—2) + (1ร—1)
= 128 + 64 + 0 + 0 + 8 + 4 + 0 + 1 = 205โ‚โ‚€

To Hexadecimal:
Group into 4-bit groups: 1100 1101
1100โ‚‚ = Cโ‚โ‚† (12 in decimal)
1101โ‚‚ = Dโ‚โ‚† (13 in decimal)
Result: CDโ‚โ‚†

Verification: Cโ‚โ‚† = 12ร—16 = 192, Dโ‚โ‚† = 13, 192+13=205 โœ“
Question 2: Perform binary addition: 1011 + 0110. Show your working and convert the result to decimal.
Answer:
Binary Addition:
   1 0 1 1 (11 in decimal)
+ 0 1 1 0 (6 in decimal)
———-
1 0 0 0 1

Working:
Column 1 (rightmost): 1 + 0 = 1
Column 2: 1 + 1 = 0, carry 1
Column 3: 0 + 1 + carry 1 = 0, carry 1
Column 4: 1 + 0 + carry 1 = 0, carry 1
Column 5: carry 1 = 1

Result: 10001โ‚‚
To decimal: 10001โ‚‚ = (1ร—16) + (0ร—8) + (0ร—4) + (0ร—2) + (1ร—1) = 16 + 0 + 0 + 0 + 1 = 17โ‚โ‚€

Verification: 11 + 6 = 17 โœ“
Question 3: Explain the advantage of two’s complement representation over sign and magnitude for representing negative numbers in computers.
Answer:
Two’s Complement Advantages:

1. Single Zero Representation: Sign and magnitude has +0 (00000000) and -0 (10000000), causing confusion and wasted values. Two’s complement has only one zero (00000000).

2. Simpler Arithmetic: Subtraction becomes addition. To compute A – B, the computer:
  a. Calculates two’s complement of B
  b. Adds it to A
This means only addition circuits are needed, simplifying hardware design.

3. Consistent Arithmetic: The same addition circuit works for both positive and negative numbers.

4. Efficient: No special cases needed for sign handling during addition.

Example: With 8-bit two’s complement, subtracting 5 from 7:
7 = 00000111, -5 = 11111011 (two’s complement of 00000101)
00000111 + 11111011 = 00000010 (with overflow discarded) = 2 โœ“
Question 4: What is the ASCII code (in decimal and binary) for the character ‘K’? How does the ASCII code for ‘k’ differ?
Answer:
ASCII for ‘K’:
Decimal: 75
Binary: 1001011 (7-bit) or 01001011 (8-bit with leading 0)
Hexadecimal: 4B

ASCII for ‘k’:
Decimal: 107
Binary: 1101011 (7-bit) or 01101011 (8-bit with leading 0)
Hexadecimal: 6B

Difference: Lowercase letters are exactly 32 decimal values higher than their uppercase counterparts in ASCII. This corresponds to flipping the 6th bit (from right, starting at 1):
‘K’: 1001011
‘k’: 1101011 (bit 6 changed from 0 to 1)

Pattern: Uppercase A-Z: 65-90, Lowercase a-z: 97-122. The difference is always 32 (2โต).
Question 5: Convert the decimal number -23 to 8-bit two’s complement representation. Show your steps.
Answer:
Steps to find -23 in 8-bit two’s complement:

1. Start with positive 23: 23โ‚โ‚€ = 00010111โ‚‚
  (16 + 4 + 2 + 1 = 23)

2. Find one’s complement (invert all bits): 11101000

3. Add 1 to get two’s complement:
  11101000 + 1 = 11101001

Result: -23โ‚โ‚€ = 11101001โ‚‚ in 8-bit two’s complement

Verification: Convert back to decimal to check:
Since MSB is 1, it’s negative. To find magnitude:
a. Invert bits: 00010110
b. Add 1: 00010111 = 23
Confirmed: -23 โœ“

Note: In two’s complement, negative numbers have their most significant bit (leftmost) set to 1.

๐ŸŽฏ Key Concepts Summary

  • Binary (Base-2): Computers’ native language using only 0s and 1s
  • Octal (Base-8) & Hexadecimal (Base-16): Shorthand for binary, easier for humans
  • Binary Addition: 1+1=0 with carry 1; similar to decimal but simpler
  • Integer Representations:
    • Sign and Magnitude: Simple but has ยฑ0
    • BCD: Accurate decimal but inefficient
    • Two’s Complement: Industry standard, simplifies arithmetic
  • ASCII: 7-bit character encoding (128 chars), extended to 8-bit (256 chars)
  • Character Patterns: Uppercase A=65, lowercase a=97, digit 0=48
  • Unicode: Modern standard supporting all languages, UTF-8 is common
  • Bit: Binary digit (0 or 1)
  • Byte: 8 bits (can represent 256 values)
  • Two’s Complement Trick: To quickly find negative: invert bits, add 1

CSEC Exam Strategy: When answering data representation questions: (1) Clearly show conversion steps, (2) Use correct notation (subscript for base), (3) For two’s complement, demonstrate the invert-and-add-1 process, (4) Remember ASCII patterns (A=65, a=97, 0=48), (5) Practice binary arithmetic with carries. Always verify your answer by converting back to decimal.

Scroll to Top