String/type Conversion (AQA GCSE Computer Science): Revision Notes
String/type conversion
What is type conversion?
Type conversion, also known as casting, is the process of changing data from one data type to another. This is essential in programming because different operations require specific data types to work properly.
String conversion specifically refers to converting data between strings and other data types (like numbers). This is particularly important because:
- User input is often received as strings
- Mathematical calculations require numeric data types
- Display output often needs to be in string format
Think of it like translating between languages - you need to convert information from one format that a computer can understand to another format that's suitable for your specific task.
AQA pseudocode conversion functions
In your GCSE Computer Science exam, you'll need to know these specific AQA pseudocode functions for type conversion:

These functions work in a straightforward way:
- STRING_TO_INT() - Takes a string containing numbers and converts it to an integer
- STRING_TO_REAL() - Takes a string containing numbers and converts it to a real (decimal) number
- INT_TO_STRING() - Takes an integer and converts it to a string
- REAL_TO_STRING() - Takes a real number and converts it to a string
Worked Example: AQA Pseudocode Conversions
# Converting strings to numbers
age ← STRING_TO_INT("16") # age now contains integer 16
price ← STRING_TO_REAL("12.99") # price now contains real 12.99
# Converting numbers to strings
score ← INT_TO_STRING(85) # score now contains string "85"
average ← REAL_TO_STRING(7.5) # average now contains string "7.5"
Real programming languages
Different programming languages have their own syntax for type conversion, but they all achieve the same goal.
Python conversion functions

Python uses simple, memorable function names:
int(x)converts to integerstr(x)converts to stringfloat(x)converts to real/floating-point number
VB.Net conversion functions

VB.Net uses functions starting with 'C' (for Convert):
CInt(x)converts to integerCStr(x)converts to stringCSng(x)converts to single-precision real number
C# conversion functions

C# uses the Convert class with descriptive method names:
Convert.ToInt32(x)converts to integerConvert.ToString(x)converts to stringConvert.ToSingle(x)converts to real number
Common errors and limitations
Critical Warning: Not all values can be successfully converted between data types. For example, trying to convert the string "hello" to an integer will cause an error because there's no logical way to turn text letters into a number.
Here's what happens when you try an impossible conversion in Python:
newval = int("hello")
This produces an error message like:
ValueError: invalid literal for int() with base 10: 'hello'
Exam tips
Key Exam Strategy Points:
- Learn the AQA pseudocode functions - These are exactly what you'll need in your exam
- Remember the direction - "STRING_TO_" functions convert FROM strings, while "_TO_STRING" functions convert TO strings
- Think about data types - Only convert values that make sense (numbers can become strings, but random text can't become numbers)
- Practice with examples - Try converting between different data types in your head
- Watch for trick questions - Exam questions might ask what happens when impossible conversions are attempted
Remember!
Essential Points to Remember:
- Type conversion (casting) changes data from one data type to another
- AQA pseudocode uses functions like STRING_TO_INT() and INT_TO_STRING()
- Real programming languages have similar functions but with different syntax (int(), CInt(), Convert.ToInt32())
- Not all conversions are possible - you can't convert meaningless text like "hello" into a number
- Direction matters - STRING_TO_INT converts FROM string TO integer, while INT_TO_STRING does the opposite