Data Representation in Computer Systems

Week 2: Binary Systems, Data Encoding & Cybersecurity Applications

Week 2 Lecture Topics | ISSE 1201

πŸ“š Lecture Topics Structure

1

Bits and Data Storage

Understanding how information is encoded as patterns of 0s and 1s inside computers. Bits represent numeric values, characters, images, and sounds.

2

Boolean Operations and Logic Gates

Boolean operations (AND, OR, XOR, NOT) and their implementation as logic gates. Gates as building blocks of computer circuits.

3

Main Memory Organization

Memory cells, addressing, and organization. RAM structure and memory capacity measurements (KB, MB, GB, TB, PB).

4

Number Systems

Binary, Decimal, Hexadecimal, and Octal systems. Conversion between different bases and their applications in computing.

5

Data Representation Methods

How different types of data are represented: text (ASCII, Unicode), numbers (integers, fractions), images (pixels, bitmaps), and sounds (sampling).

6

Integer Representation

Two's complement notation for signed integers. Overflow problem and excess notation systems.

7

Mass Storage Systems

Magnetic systems (disks, tapes), optical systems (CDs, DVDs), and flash drives. Performance evaluation criteria.

8

Binary Arithmetic

Binary addition, subtraction, and handling of fractions in binary representation.

9

Practical Tools & Commands

Using PowerShell and command-line tools to work with data representation. Practical exercises for data conversion and analysis.

10

Cybersecurity Applications

How data representation relates to encryption, forensics, malware analysis, and security protocols. Binary analysis in cybersecurity investigations.

Bits, Boolean Operations & Logic Gates

Bits - The Fundamental Unit

Bit (Binary Digit): The smallest unit of data in a computer, represented as either 0 or 1. All information inside computers is encoded as patterns of bits.

Bits represent:

  • Numeric values: Binary numbers
  • Characters: Text through encoding standards like ASCII
  • Images: As collections of pixels
  • Sounds: Through sampling of audio waves

Boolean Operations

Boolean Operation: An operation that manipulates true/false values, where bit 0 represents false and bit 1 represents true.

Basic Boolean Operations:

Operation Symbol Description Cybersecurity Application
AND ∧ Returns true only if both inputs are true Access control logic, permission checks
OR ∨ Returns true if at least one input is true Multiple authentication methods
XOR βŠ• Returns true if inputs are different Encryption algorithms, error detection
NOT Β¬ Returns the opposite of the input Complement operations in cryptography
Truth Tables for Basic Gates:

AND Gate: 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 0 = 0, 1 AND 1 = 1

OR Gate: 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1, 1 OR 1 = 1

XOR Gate: 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0

NOT Gate: NOT 0 = 1, NOT 1 = 0

Logic Gates - Building Blocks of Computers

Gate: A device that produces the output of a Boolean operation. Often implemented as small electronic circuits where 0 and 1 are represented as voltage levels.

How Gates Work:

  • AND, OR, and XOR gates take two input bits
  • NOT gate takes one input bit
  • Output is determined by the Boolean operation
  • Gates are combined to build complex circuits (adders, memory cells, processors)
∧

AND Gate

AND Logic Gate Symbol and Truth Table

Function: Output is 1 only if ALL inputs are 1.

Truth Table:
A B | Output
0 0 | 0
0 1 | 0
1 0 | 0
1 1 | 1

∨

OR Gate

OR Logic Gate Symbol and Truth Table

Function: Output is 1 if AT LEAST ONE input is 1.

Truth Table:
A B | Output
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 1

βŠ•

XOR Gate

XOR Logic Gate Symbol and Truth Table

Function: Output is 1 if inputs are DIFFERENT.

Truth Table:
A B | Output
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 0

Β¬

NOT Gate

NOT Logic Gate Symbol and Truth Table

Function: Output is the OPPOSITE of the input.

Truth Table:
Input | Output
0 | 1
1 | 0

Cybersecurity Perspective: Gate-Level Attacks

Understanding logic gates is crucial for:

  • Side-channel attacks: Analyzing power consumption or electromagnetic emissions from gates
  • Hardware security: Designing secure cryptographic circuits
  • Fault injection attacks: Manipulating gate behavior through voltage or clock glitches
  • Reverse engineering: Understanding proprietary hardware for security analysis

Memory Organization & Storage

Main Memory (RAM)

Random Access Memory: Volatile memory for storing data and programs during execution.

  • Cell: Basic unit of memory (typically 8 bits = 1 byte)
  • Address: Unique identifier for each memory cell
  • Organization: Cells organized in addressable locations
Address 0: 01011010
Address 1: 10100101
Address 2: 11110000
Address 3: 00001111
... (millions/billions of addresses)

Memory Capacity Measurements

Note: Computer memory uses binary prefixes where 1 KB = 1024 bytes (2¹⁰), not 1000 bytes.

  • Kilobyte (KB): 1024 bytes
  • Megabyte (MB): 1024 KB = 1,048,576 bytes
  • Gigabyte (GB): 1024 MB = 1,073,741,824 bytes
  • Terabyte (TB): 1024 GB = 1,099,511,627,776 bytes
  • Petabyte (PB): 1024 TB = 1,125,899,906,842,624 bytes
Memory Terminology:
  • Most Significant Bit (MSB): Leftmost bit in a byte
  • Least Significant Bit (LSB): Rightmost bit in a byte
  • Higher-order end: Left end of bit sequence
  • Lower-order end: Right end of bit sequence

Mass Storage Systems

Why Mass Storage? Main memory is volatile and limited in size, so computers need additional storage.

Advantages

  • Less volatility (data persists without power)
  • Large storage capacity
  • Lower cost per byte
  • Removable media for archiving

Disadvantages

  • Slower access (mechanical motion)
  • Higher latency
  • Physical wear and tear
  • Susceptible to physical damage
Types of Mass Storage:
  • Magnetic Systems: Hard disks, tapes (tracks and sectors)
  • Optical Systems: CDs, DVDs, Blu-ray (pits and lands)
  • Flash Memory: SSDs, USB drives, memory cards (electronic storage)

Cybersecurity: Storage Forensics & Data Recovery

Understanding storage systems is essential for:

  • Digital forensics: Recovering deleted files from disk sectors
  • Data recovery: Understanding file systems and storage layouts
  • Secure deletion: Knowing how data persists on different media
  • Storage encryption: Implementing full-disk encryption
  • Anti-forensics: Techniques to hide or destroy digital evidence

Number Systems & Data Representation

Number Systems Comparison

System Base Digits Example Bits per Digit Primary Use
Binary 2 0, 1 1101 1 Computer internal operations
Decimal 10 0-9 42 ~3.32 Human counting
Octal 8 0-7 52 3 UNIX permissions, historical systems
Hexadecimal 16 0-9, A-F 2A 4 Memory addresses, color codes
Key Conversion Relationships:

β€’ 1 Hexadecimal digit = 4 Binary digits (bits)

β€’ 1 Octal digit = 3 Binary digits (bits)

β€’ 3 Octal digits = 1 Byte (8 bits, with 1 bit unused)

β€’ 2 Hexadecimal digits = 1 Byte (8 bits)

Number System Conversion Methods

Conversion Fundamentals: All number systems follow the same positional notation principle. Each digit's value = digit Γ— (baseposition), where position starts at 0 from right.

Conversion Type Primary Method Shortcut/Alternative Cybersecurity Application
Decimal β†’ Binary Repeated Division by 2 Subtraction of Powers of 2 IP subnet calculations, bitmask operations
Binary β†’ Decimal Sum of (digit Γ— 2position) Double-dabble algorithm Memory address calculation, packet analysis
Decimal → Hex Repeated Division by 16 Convert via binary (Dec→Bin→Hex) Memory dump analysis, hex editors
Hex → Decimal Sum of (digit × 16position) Convert via binary (Hex→Bin→Dec) Reverse engineering, malware analysis
Binary ↔ Hex Group binary digits in 4s Direct mapping (0000=0, 1111=F) Compact representation of binary data
Binary ↔ Octal Group binary digits in 3s Direct mapping (000=0, 111=7) UNIX file permission analysis
Decimal to Binary Conversion

Method 1: Repeated Division

Example: Convert 4210 to binary

42 Γ· 2 = 21 remainder 0 (LSB)
21 Γ· 2 = 10 remainder 1
10 Γ· 2 = 5 remainder 0
5 Γ· 2 = 2 remainder 1
2 Γ· 2 = 1 remainder 0
1 Γ· 2 = 0 remainder 1 (MSB)

Result: Read remainders from bottom to top: 1010102

Method 2: Subtraction of Powers of 2

Example: Convert 4210 to binary

42 - 32 = 10 (25 = 32 β†’ bit position 5 = 1)
10 - 8 = 2 (23 = 8 β†’ bit position 3 = 1)
2 - 2 = 0 (21 = 2 β†’ bit position 1 = 1)
Other positions get 0

Result: 1010102 (32+8+2 = 42)

Binary to Decimal Conversion

Positional Weight Method

Example: Convert 1010102 to decimal

Position 5 (from right): 1 Γ— 25 = 1 Γ— 32 = 32
Position 4: 0 Γ— 24 = 0 Γ— 16 = 0
Position 3: 1 Γ— 23 = 1 Γ— 8 = 8
Position 2: 0 Γ— 22 = 0 Γ— 4 = 0
Position 1: 1 Γ— 21 = 1 Γ— 2 = 2
Position 0: 0 Γ— 20 = 0 Γ— 1 = 0

Result: 32 + 0 + 8 + 0 + 2 + 0 = 4210

πŸ’‘ Quick Mental Calculation:

For binary numbers: Remember powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024...

Binary ↔ Hexadecimal Conversion

Binary to Hex: Group in 4s

Example: Convert 1101101010112 to hex

Group: 1101 1010 1011
11012 = D16 (8+4+0+1 = 13)
10102 = A16 (8+0+2+0 = 10)
10112 = B16 (8+0+2+1 = 11)

Result: DAB16

Hex to Binary: Expand each digit

Example: Convert 2F516 to binary

216 = 00102
F16 = 11112 (15)
516 = 01012

Result: 0010 1111 01012 = 10111101012

Decimal ↔ Hexadecimal Conversion

Decimal to Hex: Repeated Division by 16

Example: Convert 35010 to hex

350 Γ· 16 = 21 remainder 14 (E) (LSB)
21 Γ· 16 = 1 remainder 5
1 Γ· 16 = 0 remainder 1 (MSB)

Result: Read remainders bottom to top: 15E16

Hex to Decimal: Positional Weight

Example: Convert 2A316 to decimal

Position 2: 2 Γ— 162 = 2 Γ— 256 = 512
Position 1: A(10) Γ— 161 = 10 Γ— 16 = 160
Position 0: 3 Γ— 160 = 3 Γ— 1 = 3

Result: 512 + 160 + 3 = 67510

Binary ↔ Octal Conversion

Binary to Octal: Group in 3s

Example: Convert 1011100112 to octal

Group: 101 110 011 (add leading 0 if needed)
1012 = 58 (4+0+1 = 5)
1102 = 68 (4+2+0 = 6)
0112 = 38 (0+2+1 = 3)

Result: 5638

Octal to Binary: Expand each digit

Example: Convert 3478 to binary

38 = 0112
48 = 1002
78 = 1112

Result: 011 100 1112 = 111001112

Practical Tools & PowerShell Commands

Windows Calculator (Programmer Mode)

Open Calculator β†’ View β†’ Programmer
Select input base (DEC, HEX, OCT, BIN)
Enter number, switch bases to see conversions

PowerShell Conversion Commands

# Decimal to Binary
[Convert]::ToString(42, 2) # Returns: 101010

# Binary to Decimal
[Convert]::ToInt32("101010", 2) # Returns: 42

# Decimal to Hexadecimal
[Convert]::ToString(255, 16) # Returns: ff

# Hexadecimal to Decimal
[Convert]::ToInt32("FF", 16) # Returns: 255

Cybersecurity Applications of Number Conversion

Understanding number system conversions is essential in cybersecurity for:

  • Memory Forensics: Reading hex dumps, understanding memory addresses
  • Malware Analysis: Analyzing binary code, understanding opcodes
  • Network Security: IP address calculations (IPv4 in decimal-dot to binary)
  • Cryptography: Working with hex representations of encrypted data
  • Digital Forensics: Interpreting file headers, analyzing disk sectors
  • Reverse Engineering: Converting between assembly representations
  • Log Analysis: Understanding hex-encoded log entries
πŸ” Real-World Example: IP Address Conversion

IPv4 address 192.168.1.1 in binary:

192 = 11000000
168 = 10101000
1 = 00000001
1 = 00000001

Full binary: 11000000.10101000.00000001.00000001

Hex: C0.A8.01.01 (used in network packet analysis)

Text Representation

Character Encoding Standards:

  • ASCII (7-bit): 128 characters, English text
  • Extended ASCII (8-bit): 256 characters, includes symbols
  • Unicode (UTF-8, UTF-16): Supports all languages
    • UTF-8: Variable length (1-4 bytes), backward compatible with ASCII
    • UTF-16: Fixed 2 or 4 bytes per character
# "Hello." in ASCII (hex values)
H: 48 e: 65 l: 6C l: 6C o: 6F .: 2E
# Binary: 01001000 01100101 01101100 01101100 01101111 00101110

Image & Sound Representation

Images:

  • Pixel (Picture Element): Smallest unit of an image
  • Bitmap: Collection of encoded pixels
  • Black & White: 1 bit per pixel (0=black, 1=white)
  • Color (RGB): 3 bytes per pixel (1 byte each for Red, Green, Blue)

Sounds:

  • Sampling: Measuring amplitude at regular intervals
  • Sample rate: How often amplitude is measured (Hz)
  • Bit depth: Number of bits per sample

Integer Representation: Two's Complement

Two's Complement: The most common method for representing signed integers in computers. Negative numbers are represented as the two's complement of their absolute value.

Key Features:

  • Leftmost bit represents sign (0 = positive, 1 = negative)
  • Range for n bits: -2ⁿ⁻¹ to 2ⁿ⁻¹ - 1
  • Single representation for zero
  • Simple addition/subtraction circuits
Decimal 4-bit Two's Complement Calculation
+7 0111 Largest positive
+1 0001 1 in binary
0 0000 Zero
-1 1111 Invert bits of 1 and add 1
-8 1000 Smallest negative
Overflow Problem:

When using 4-bit two's complement, the range is -8 to +7. Adding 5 + 4 = 9, which is outside this range, causes overflow. The result 0101 + 0100 = 1001, which is -7 in two's complement, not 9.

🏫 In-Class Practical Activities

πŸ” Activity 1: Number System Conversions

Objective: Practice converting between different number systems

  • Convert decimal 42 to binary, octal, and hexadecimal
  • Convert binary 11011010 to decimal, octal, and hexadecimal
  • Convert hexadecimal 2A to decimal, binary, and octal
  • Convert octal 75 to decimal, binary, and hexadecimal
# PowerShell conversion examples
[Convert]::ToString(42, 2) # Decimal to binary
[Convert]::ToString(42, 8) # Decimal to octal
[Convert]::ToString(42, 16) # Decimal to hex
[Convert]::ToInt32("11011010", 2) # Binary to decimal

πŸ” Activity 2: Boolean Logic & Gate Analysis

Objective: Analyze logic circuits and create truth tables

  • Create truth tables for AND, OR, XOR, NAND, and NOR gates
  • Analyze the circuit: NOT(AND(OR(A,B), C))
  • Determine input patterns that produce output 1 for given circuits
  • Design a circuit that outputs 1 only when exactly two inputs are 1
Gate Circuit Analysis:

For the circuit: Input β†’ NOT β†’ AND β†’ Output, with another input going directly to AND. What inputs produce output 1?

πŸ” Activity 3: Data Representation Exercises

Objective: Work with different data representation methods

  • Convert the text "CYBER" to ASCII binary representation
  • Calculate storage needed for a 1920Γ—1080 color image (24-bit RGB)
  • Represent decimal -15 in 8-bit two's complement
  • Convert 0.625 (decimal) to binary fraction
  • Calculate the range of integers representable with 16-bit two's complement
# Converting text to ASCII values in PowerShell
[System.Text.Encoding]::ASCII.GetBytes("CYBER")
# Returns: 67 89 66 69 82

# Converting decimal fraction to binary manually:
# 0.625 Γ— 2 = 1.25 β†’ 1 (MSB)
# 0.25 Γ— 2 = 0.5 β†’ 0
# 0.5 Γ— 2 = 1.0 β†’ 1 (LSB)
# Result: 0.101 binary

βœ… Solutions for In-Class Activities

Activity 1 Solutions: Number System Conversions

1. Decimal 42 to binary, octal, hexadecimal:

  • Binary: 1010102
  • Octal: 528
  • Hexadecimal: 2A16

2. Binary 11011010 to decimal, octal, hexadecimal:

  • Decimal: 21810 (128+64+0+16+8+0+2+0 = 218)
  • Octal: 3328 (011 011 010 = 3 3 2)
  • Hexadecimal: DA16 (1101 1010 = D A)

3. Hexadecimal 2A to decimal, binary, octal:

  • Decimal: 4210 (2Γ—16 + 10Γ—1 = 32+10 = 42)
  • Binary: 001010102 (2=0010, A=1010)
  • Octal: 528 (001 010 101 = 1 2 5, but grouping correctly: 101010 = 52)

4. Octal 75 to decimal, binary, hexadecimal:

  • Decimal: 6110 (7Γ—8 + 5Γ—1 = 56+5 = 61)
  • Binary: 1111012 (7=111, 5=101)
  • Hexadecimal: 3D16 (0011 1101 = 3 D)
Activity 2 Solutions: Boolean Logic & Gate Analysis

Truth Tables for Basic Gates:

A B AND OR XOR NAND NOR
0000011
0101110
1001110
1111000

Circuit Analysis: NOT(AND(OR(A,B), C))

First, OR(A,B) produces 1 if A=1 OR B=1. Then AND with C produces 1 only if both OR(A,B)=1 AND C=1. Finally, NOT inverts the result.

Circuit that outputs 1 only when exactly two inputs are 1:

For three inputs A, B, C: Output = (A AND B AND NOT C) OR (A AND C AND NOT B) OR (B AND C AND NOT A)

Activity 3 Solutions: Data Representation Exercises

1. "CYBER" in ASCII binary:

  • C: 6710 = 010000112
  • Y: 8910 = 010110012
  • B: 6610 = 010000102
  • E: 6910 = 010001012
  • R: 8210 = 010100102

2. Storage for 1920Γ—1080 color image (24-bit RGB):

  • Total pixels = 1920 Γ— 1080 = 2,073,600 pixels
  • Bits per pixel = 24 bits (3 bytes)
  • Total bits = 2,073,600 Γ— 24 = 49,766,400 bits
  • Total bytes = 49,766,400 Γ· 8 = 6,220,800 bytes β‰ˆ 5.93 MB

3. Decimal -15 in 8-bit two's complement:

  • +15 in binary: 00001111
  • Invert bits: 11110000
  • Add 1: 11110001
  • Result: 111100012

4. 0.625 decimal to binary fraction:

  • 0.625 Γ— 2 = 1.25 β†’ 1 (MSB)
  • 0.25 Γ— 2 = 0.5 β†’ 0
  • 0.5 Γ— 2 = 1.0 β†’ 1 (LSB)
  • Result: 0.1012

5. Range for 16-bit two's complement:

  • Minimum: -215 = -32,768
  • Maximum: 215 - 1 = 32,767
  • Range: -32,768 to 32,767

Homework Assignment - Week 2

Submission Method: PDF document via Google Classroom

Instructions: Answer all questions in your own words. Show all work for calculations and programming exercises.

Part 1: Number System Conversions (40 points)

  1. Convert the following decimal numbers to binary, octal, and hexadecimal: (15 points)
    • 37
    • 125
    • 255
  2. Convert the following binary numbers to decimal, octal, and hexadecimal: (15 points)
    • 11001101
    • 10101010
    • 11110000
  3. Perform the following conversions: (10 points)
    • Octal 347 to binary and hexadecimal
    • Hexadecimal 2F5 to binary and decimal

Part 2: Boolean Logic & Data Representation (40 points)

  1. Complete the truth tables for the following logic gates: (15 points)
    • AND gate (inputs A, B)
    • OR gate (inputs A, B)
    • XOR gate (inputs A, B)
    • NAND gate (inputs A, B)
  2. Analyze the circuit: NOT(OR(AND(A,B), C)). Create a complete truth table for all possible input combinations (A, B, C). (10 points)
  3. Data Representation Problems: (15 points)
    • Convert the text "SECURITY" to ASCII binary representation
    • Represent decimal -27 in 8-bit two's complement
    • Convert 0.375 (decimal) to binary fraction

Part 3: Practical Applications (20 points)

  1. IP Address Conversion: Convert the IPv4 address 172.16.254.1 to binary and hexadecimal representations. (10 points)
  2. Memory Calculation: If a computer has 8 GB of RAM, how many memory addresses can it theoretically access (assuming byte-addressable memory)? Show your calculations. (10 points)

Submission Guidelines

  • Include your name, student ID, and "Week 2 Homework" at the top of the document
  • Organize your answers clearly with question numbers and parts
  • Show all work for calculations (don't just provide final answers)
  • For truth tables, use proper formatting (rows and columns)
  • Submit as a single PDF file named: "YourName_ID_Week2_HW.pdf"
πŸ’‘ Tips for Success:
  • Use the Windows Calculator in Programmer mode to verify your conversions
  • Practice with PowerShell commands for number conversions
  • Draw circuits and truth tables on paper before writing final answers
  • Review the in-class activities before attempting the homework

From Bits to Security: Building Your Foundation

Understanding how data is represented at the binary level is not just academic knowledge - it's the foundation of cybersecurity. Every encryption algorithm, every forensic analysis, and every security protocol operates on these fundamental principles.

As cybersecurity engineers, you need to understand systems at their most basic level to effectively protect them, analyze attacks, and design secure solutions.

πŸ“… Next Week Preview:

Computer Architecture & Processing - We'll explore how computers process data at the hardware level. Topics include CPU architecture, memory hierarchy, instruction execution, and how processing relates to system performance and security vulnerabilities like buffer overflows and side-channel attacks.

Access Week 3 Complete Materials