Wednesday 8 February 2017

1.3 Basic operations in programming

  • Variable: a data item whose value will change during the execution of the program
  • Arithmetic operation: common expressions such as +, -, /, x
  • Rounding: reducing the number of digits used to represent a number while maintaining a value that is approximately equivalent
  • Truncating: the process of cutting off a number after a certain number of characters or decimal places
  • Random number generation: a function that produces a completely random number
  • Pseudo-random number generator: common in programming languages, a function that produces a random that is not 100% random
  • Relational operations: expressions that compare two values such as equal to or greater than
  • Boolean operators: expressions that result in a TRUE or FALSE value
  • AND: boolean operation that outputs true if both inputs are true
  • OR: Boolean operation that outputs true if either of its inputs are true
  • NOT: Boolean operation that inverts the result so true becomes false and false becomes true
  • XOR: Boolean operation that is true if either input is true but not if both inputs are true
  • String-handling functions: actions that can be carried out on sequences of characters
  • Character code: a binary representation of a particular letter, number or special character

Arithmetic operations
  • Addition
  • Subtraction
  • Multiplication
  • Division of real numbers: A real number is one with a fractional part
  • Example: 3.1 = 6.2 / 2
  • Division of integers: An integer is a whole number and therefore may generate a number with a remainder
  • Example: 3r1 = 7 / 2
  • Modulo operation: MOD operation is used to divide one number by another to find the remainder
  • Exponentiation
  • Rounding
  • Truncating: Shortening a value by cutting it off after a certain number of digits
  • It is the equivalent of rounding down
  • Random number generator: creating a number to be used in a program that is random
  • Random numbers are very useful
  • Typical applications include:
    • A range of test data
    • Computer simulations
    • Creating random events and movements in computer games
    • Selecting a random sample from a dataset
  • Most random number generation techniques used in programming languages start from a seed value and then use an algorithm to create the random number, it means that the number cannot be truly random as the algorithm used will produce an element of structure to the results
  • Random numbers generated by programming languages are often referred to as pseudo-random numbers
  • In other circumstances, such as encryption, this level of randomness would not be sufficient

Relational operations
  • Relational operations work by making comparisons between two data items
  • Operands are the values and the operator is the comparison being made

Boolean operations
  • Fundamental to the process of searching data whether that is in a database, or on the web
  • The four basic operations are:
    • AND: known as conjunction
    • OR: known as disjunction
    • NOT: known as a negation
    • XOR: known as exclusive OR
  • It is possible to embed relational operations within boolean operations

String-handling functions

  • Length: there is usually an upper limit places on its size
  • You can set the maximum length or calculate the length of a particular string of data
  • Position: find the start position of a particular string of characters within another string
  • Substring: Various techniques can be used to extract data from anywhere in a string to create a substring providing the start and end position are known or the start position and length are known
  • Concatenation: adding strings together
  • Character codes: convert a text value to a numeric value i order to carry out a calculation on it, especially when encrypting data
  • String to integer / integer to string
  • String to float / float to string: a float is also called a real number
  • String to datetime / datetime string

No comments:

Post a Comment