Pre-defined functions
Predefined functions are built-in tools that come with the programming language. You can use them to carry out common tasks without writing all the code yourself. Below are some key examples used in Higher Computing Science:
Modulus
-
Gives the remainder when one number is divided by another
-
Example: 7 divided by 3 gives a remainder of 1
-
Used to check for even or odd numbers, or repeating patterns
Integer conversion
- Converts a decimal number into a whole number
- Example: converting 4.9 gives 4
- It does not round, it simply removes the decimal part
- Useful when you only need the whole part of a number
Modulus
- A substring is part of a longer string
- You choose a start and end position to extract it
- Example: the first three letters of “Hello” would be “Hel”
- Useful for working with initials, codes, or sections of text
Character to ASCII
- Converts a letter or symbol into its ASCII number
- Example: the letter A becomes 65
- Useful for comparing letters or working with encryption
ASCII to character
- Converts an ASCII number into the matching character
- Example: the number 66 becomes the letter B
- Used when turning numbers back into text, such as in code-breaking