0.4.17 Module 4 Quiz Study Guide

Number Systems Represent Values in Different Bases

Module 4 began by comparing decimal, binary, and hexadecimal.

Decimal

Base 10.

Digits:

Plain text
0 through 9

Place values grow by powers of 10.

Binary

Base 2.

Digits:

Plain text
0 and 1

Place values grow by powers of 2.

Hexadecimal

Base 16.

Digits:

Plain text
0 through 9 and A through F

Place values grow by powers of 16.

The same quantity can have different written representations.

For example:

Plain text
Decimal:      15
Binary:       1111
Hexadecimal:  F

The representation changes.

The quantity does not.

Four Binary Bits Correspond to One Hexadecimal Digit

Four bits provide sixteen possible patterns.

One hexadecimal digit also provides sixteen possible values.

That creates a direct mapping:

Plain text
0000 ↔ 0
0001 ↔ 1
...
1010 ↔ A
1011 ↔ B
1100 ↔ C
1101 ↔ D
1110 ↔ E
1111 ↔ F

This makes hexadecimal a compact way to represent binary patterns.

Bits Are Binary Digits

A bit contains one binary value:

Plain text
0

or:

Plain text
1

Eight bits form a byte.

A pattern of bits does not automatically tell you its meaning.

A system can interpret bit patterns as:

The representation needs context.

Information Has a Type

Programs need to know what kind of information a value represents.

Important introductory categories include:

The meaning of the information should guide the type choice.

Common Basic C# Types

Four useful introductory C# types are:

C#
string
int
double
bool

Examples:

C#
string playerName = "Jordan";
int jerseyNumber = 7;
double heightMeters = 1.82;
bool isAvailable = true;

The type tells C# what kind of value the variable is intended to hold.

UML Class Diagrams Describe Kinds of Objects

An object diagram shows a specific instance:

Plain text
player1 : Player
-------------------------
jerseyNumber = 7

A class diagram shows the structural definition:

Plain text
Player
-------------------------
jerseyNumber : int

The class diagram describes what Player objects can contain.

The object diagram shows what one Player object contains at a particular moment.

UML Attributes Can Include Types

A common attribute form is:

Plain text
attributeName : Type

For example:

Plain text
Player
--------------------------------
name : string
jerseyNumber : int
heightMeters : double
isAvailable : bool

The name explains what the information means.

The type explains what kind of value it can contain.

Object, Activity, and Class Diagrams Have Different Purposes

Object diagram

Focus:

What specific objects and values exist right now?

Activity diagram

Focus:

What actions happen, in what order, and along which path?

Class diagram

Focus:

What classes exist, and what information can those kinds of objects contain?

Choose the diagram based on the question being answered.

Memory and Persistent Storage Are Different

The running program works with current information in memory.

Examples include:

Persistent storage keeps information available beyond the current execution.

A text file is one simple persistent-storage mechanism.

The core distinction is:

Plain text
Memory → current running state
File storage → information that can survive after the program closes

Writing Moves Information to Persistent Storage

A simple C# write is:

C#
System.IO.File.WriteAllText("lineup.txt", lineupNote);

Conceptually:

Plain text
runtime text
    ↓
write
    ↓
text file

WriteAllText writes the supplied text as the file's complete content.

Reading Brings Information Back Into Memory

A simple C# read is:

C#
string lineupNote =
    System.IO.File.ReadAllText("lineup.txt");

Conceptually:

Plain text
text file
    ↓
read
    ↓
runtime string

The file remains persistent.

The program now also has the contents available in memory.

Writing and Reading Do Not Automatically Save Whole Objects

A Player object may contain several fields.

Writing a text file stores only the text the program chooses to write.

Reading a text file returns text.

Turning complex object state into a structured file representation is a separate problem.

That work is outside the current module.

Activity Diagrams Can Model Information Movement

A simple save process can be represented as:

Plain text
Start
  ↓
Enter information
  ↓
Hold information in running application
  ↓
Write information to text file
  ↓
End

A load process can be represented as:

Plain text
Start
  ↓
Read information from text file
  ↓
Hold information in running application
  ↓
Display information
  ↓
End

The diagram shows the process.

C# supplies the executable instructions.

The Module 4 Story

The major progression is:

Represent values → Identify their types → Model class structure → Distinguish runtime memory from persistent storage → Write information → Read information

These ideas connect representation and storage.

A digital system needs both: