Study guide

7.1 Variables, Data Types, and Type Conversion

Praxis Computer Science 5652

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Praxis 5652 Exam Overview and ETS Pseudocode

1.1 Praxis 5652 Test Facts, Scoring, and Registration 1.2 Official ETS Pseudocode Notation and Tracing Strategy

2 Chapter 2: Impacts of Computing: Innovation, Access, and Effects

2.1 Computing for Creativity, Problem Solving, Communication, and Innovation 2.2 Equal Access, the Digital Divide, and Accessibility 2.3 Beneficial and Harmful Effects of Computing Innovations

3 Chapter 3: Impacts of Computing: Intellectual Property, Ethics, Privacy, and Security

3.1 Intellectual Property: Copyright, Open Source, and Creative Commons 3.2 Ethical and Unethical Computing Practices and Their Implications 3.3 Privacy, Security, Data Collection, and Local vs. Cloud Storage

4 Chapter 4: Algorithms and Computational Thinking: Abstraction, Decomposition, Number Bases, and Representation

4.1 Abstraction and Abstraction Hierarchies 4.2 Decomposition, Pattern Recognition, and Developing Algorithms 4.3 Number Bases: Binary, Octal, Decimal, and Hexadecimal 4.4 Algorithm Formats: Natural Language, Flowcharts, Pseudocode, and Tracing

5 Chapter 5: Algorithms: Efficiency, Limits of Computing, and Randomization

5.1 Algorithm Efficiency: Linear, Quadratic, Exponential, and Logarithmic Growth 5.2 Limits of Computing: Unsolvable Problems, Intractability, and Heuristics 5.3 Randomization, Random vs. Pseudorandom Numbers, and Scaling to a Range

6 Chapter 6: Algorithms: Searching, Sorting, and Recursion

6.1 Searching Algorithms: Linear Search and Binary Search 6.2 Sorting Algorithms: Tracing, Comparisons, Correctness, and Efficiency 6.3 Recursion: Base Cases, Tracing, Errors, and Iterative Equivalents

7 Chapter 7: Programming: Variables, Data Types, Strings, and Expressions

7.1 Variables, Data Types, and Type Conversion 7.2 Strings and String Operations 7.3 Operators, Precedence, Expressions, and Formulas 7.4 Boolean Expressions, Truth Tables, and Boolean Algebra

8 Chapter 8: Programming: Selection, Iteration, and Writing Code

8.1 Sequence and Selection: if, else, Chained and Nested Conditions 8.2 Iteration: for, while, do … while, and repeat … until Loops 8.3 Reading, Completing, and Modifying Code

9 Chapter 9: Programming: Procedures, Arrays, and Data Structures

9.1 Procedures, Parameters, Return Values, Nested Calls, and Scope 9.2 Arrays, Lists, and Two-Dimensional Arrays 9.3 Stacks, Queues, and Dictionaries (Maps)

10 Chapter 10: Programming: Correctness, Errors, Testing, and Code Quality

10.1 Program Correctness: Preconditions, Postconditions, Invariants, and Testing vs. Proof 10.2 Error Types and Debugging Techniques 10.3 Choosing Useful Test Cases: Boundaries, Partitions, Coverage, and Regression 10.4 Extensibility, Modifiability, and Reusability: Constants and Parameterization 10.5 Documentation, Code Reviews, Peer Feedback, and End-User Feedback

11 Chapter 11: Programming: Events, Usability, Input Validation, and APIs

11.1 Event-Driven Programming, Asynchronous Events, and Concurrency 11.2 Usability, Meaningful Error Messages, and Input Validation vs. Verification 11.3 Libraries and APIs: Reading Definitions, Making Calls, and Weighing Trade-offs

12 Chapter 12: Programming: Languages, Tools, Paradigms, and Object-Oriented Design

12.1 Low- and High-Level Languages, Compilers and Interpreters, and IDEs 12.2 Programming Paradigms: Procedural, Object-Oriented, and Others 12.3 Classes, Objects, Instance Variables, Methods, and Encapsulation 12.4 Inheritance, Polymorphism, and Overloading vs. Overriding

13 Chapter 13: Data: Bits, Encoding, Compression, and Encryption

13.1 Bits and Bytes: Why Binary, Storage Calculations, and Signed Integers 13.2 Encoding Text, Images, and Sound 13.3 Lossless and Lossy Compression: Run-Length Encoding, Huffman Coding, and Media Formats 13.4 Encoding vs. Encryption, Symmetric and Public-Key Encryption, and Their Trade-offs

14 Chapter 14: Data: Analysis Tools, Simulation, Storage, and Collection

14.1 Analyzing Data with Spreadsheets: Cleaning, Transforming, and Visualizing 14.2 Simulation and Modeling 14.3 Files, Databases, and Storage Requirements: Scale, Redundancy, and Backup 14.4 Collecting, Aggregating, and Generating Data: Public Data Sets, Surveys, Sensors, and Crowdsourcing

15 Chapter 15: Computing Systems: Hardware, Operating Systems, and Computing Environments

15.1 Hardware Components and the Fetch–Decode–Execute Cycle 15.2 Operating Systems, Software Components, and Resource Issues 15.3 Embedded Systems, the Internet of Things, and Types of Computing Systems 15.4 Local, Network, and Cloud Computing and Storage; How Binary Data Are Stored

16 Chapter 16: Networks, the Internet, the Web, and Cybersecurity

16.1 Network Types and Wired and Wireless Communication 16.2 Network Hardware and Layered Network Models (OSI and TCP/IP) 16.3 Network Performance: Bandwidth, Latency, Load, and Estimating Needs 16.4 How the Internet Works: Protocols, IP Addressing, DNS, URLs, and Reliability 16.5 The Web: HTTP, HTML and Markup Languages, Browsers, Servers, and Clients 16.6 Cybersecurity: The Five Pillars, Strong Passwords, Security Strategies, and Trade-offs

7.1 Variables, Data Types, and Type Conversion

Key Takeaways Explain This Topic AI

The ETS pseudocode data types are boolean, char, double, float, int, int[ ], int[ ][ ], short, and String.

Integer types store whole numbers exactly within a fixed range; floating-point types (float, double) store fractional values approximately.

Integer division discards the fractional part (17 / 5 is 3), while floating-point division keeps it (17.0 / 5 is 3.4); the remainder operator % gives 17 % 5 = 2.

Type conversion is needed when data arrive in the wrong type, such as text input "42" that must become the number 42, or integers that must be averaged as floating-point values.

Converting a floating-point value to an integer typically truncates toward zero, so 87.85 becomes 87 and −4.8 becomes −4.

Last updated: September 2026

What this competency asks

ETS asks you to understand how to use variables and a variety of data types , including integers, floating point, strings, Booleans, and arrays or lists. Beyond tracing code, the listed skills include:

Identify variables and data types, and the need for type conversion .

Describe the difference between integer and floating-point numeric types, and between integer and floating-point division .

Describe the benefits of each data type and identify the most appropriate type in a context.

Distinguish global and local scope (Section 9.1) and sequence string operations (Section 7.2).

Variables

A variable is a named storage location whose value can change. In ETS pseudocode, a variable is declared with its type and usually given an initial value in the same line: int count ← 0

  • double price ← 19.99
  • boolean done ← false
  • char grade ← 'A'
  • String name ← "Ada"
  • int[ ] scores ← {90, 85, 77}

Declaration tells the program the name and type. Initialization gives the first value. Assignment ( ← ) replaces the stored value: in count ← count + 1 , the right side is evaluated using the old value, and the result then overwrites count .

A constant is a named value that should not change, such as a tax rate or a maximum class size. Using named constants instead of repeated literal numbers makes code easier to read and change (Section 10.4).

The data types in ETS pseudocode

  • Type Holds Typical size* Good for
  • boolean true or false — Flags and conditions: isEnrolled , found
  • char One character 16 bits (Java) A letter grade, a single key press
  • short Small whole numbers 16 bits (−32,768 to 32,767) Memory-conscious small counts
  • int Whole numbers 32 bits (about ±2.1 billion) Counts, indexes, ages, quantities

float Approximate real numbers 32 bits (about 7 significant digits) Measurements where modest precision is enough

double Approximate real numbers 64 bits (about 15–16 significant digits) Averages, measurements, scientific values

  • String A sequence of characters Varies Names, messages, text input
  • int[ ] A list of int values Varies A set of scores
  • int[ ][ ] A grid of int values Varies Seating charts, game boards, images

*Sizes shown are the Java conventions most textbooks use. The ETS notation table lists the types without sizes.

Choosing the most appropriate type

  • Situation Best type Why
  • Number of students in a class int Whole number; exact
  • Average of several test scores double May have a fractional part
  • Whether homework was submitted boolean Only two states
  • A student's middle initial char One character
  • A student's full name String Many characters
  • Daily high temperatures for a month double[ ] or int[ ] Many values of the same type
  • Tic-tac-toe board char[ ][ ] or int[ ][ ] Rows and columns
  • Phone number or ZIP code String Not used in arithmetic; may begin with 0

A classic trap: a ZIP code such as 02134 looks numeric, but storing it as an int drops the leading zero, and you never add ZIP codes together. Identifiers such as these belong in a String .

Integer vs. floating-point types

  • Integer types ( short , int ) Floating-point types ( float , double )
  • Values Whole numbers only Numbers with fractional parts, and very large or small magnitudes
  • Exactness Exact within the range Approximate: many decimals, such as 0.1, cannot be stored exactly
  • Main risk Overflow past the maximum value Round-off error; comparing with == is unreliable
  • Typical uses Counting, indexing, looping Measurements, averages, scientific calculations

Because floating-point values are stored in binary, 0.1 + 0.2 is not exactly 0.3 in most languages. Compare floating-point results with a tolerance, such as abs ( a - b ) < 0.0001 , instead of with == . For money, many programs store whole cents in an integer type to avoid round-off.

Integer vs. floating-point division

  • Expression Result Reason
  • 17 / 5 (both integers) 3 Integer division discards the fraction
  • 17 % 5 2 Remainder: 17 = 5 × 3 + 2
  • 17.0 / 5 3.4 A floating-point operand gives floating-point division
  • 7 / 2 (integers, Java) −3 Java truncates toward zero

In ETS pseudocode, remember the rule from Section 1.2. The notation table says / is floating-point division unless stated otherwise, but ETS's sample explanations treat / between two int values as integer division. Read the declared types and the answer choices.

The average trap. In Java, if sum and count are both int , then double avg = sum / count; performs integer division before the result is stored. With sum = 17 and count = 4, avg is 4.0, not 4.25. Converting one operand first, as in (double) sum / count , gives 4.25.

When type conversion is needed

Type conversion changes a value from one type to another.

  • Need Example
  • Text input used as a number The user types "42"; convert the String to an int before adding
  • A number shown as text "Total: " + 42 produces the String "Total: 42" through concatenation
  • An accurate average of integers Convert sum or count to double before dividing
  • Storing a real number as an integer Convert 3.99 to an int (truncation gives 3)
  • Comparing a character with a code 'A' has the numeric code 65 in ASCII and Unicode

Widening conversions (such as int → double ) happen automatically in most languages because the target can represent the value's range. Even so, very large integers can lose precision when converted to float . Narrowing conversions (such as double → int ) usually require an explicit cast because information can be lost. When a floating-point value is cast to an integer, the fractional part is truncated toward zero : (int) 3.9 is 3 and (int) -4.8 is −4. It is not rounded.

How the types are stored

All types are ultimately bit patterns. Integers use two's complement binary, and floating-point numbers use the IEEE 754 format (sign, exponent, fraction). Characters are stored as numeric codes (ASCII or Unicode), and Booleans as a bit or a byte. Arrays store their elements in consecutive memory locations. Chapter 13 explains these representations in detail.