Operators & Identifiers The Data Elements
Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division ( integer remainder ) addition Subtraction assignment ^ * / \ Mod + - =
Evaluate these expressions = 100 / 10 / 5 = 100 / 10 \ 5 = 100 \ 10 / 5 = Mod 5 = \ 5
Evaluate these expressions = 100 / 10 / 52 = 100 / 10 \ 5 = 100 \ 10 / 5 = Mod 5 = \ 5
Evaluate these expressions = 100 / 10 / 52 = 100 / 10 \ 52 = 100 \ 10 / 5 = Mod 5 = \ 5
Evaluate these expressions = 100 / 10 / 52 = 100 / 10 \ 52 = 100 \ 10 / 550 = Mod 5 = \ 5
Evaluate these expressions = 100 / 10 / 52 = 100 / 10 \ 52 = 100 \ 10 / 550 = Mod 5100 = \ 5
Evaluate these expressions = 100 / 10 / 52 = 100 / 10 \ 52 = 100 \ 10 / 550 = Mod 5100 = \ 5102
Variables A variable is a string used to identify a memory location. The amount of memory is determined by the type of data that it will store. Typically, variable names need to be declared so the operating system can allocate sufficient space. Then values of the specified type can be assigned, i.e. stored in that location.
Variable names Must begin with a letter –Can include letters and numerals –Cannot include spaces Use names that are descriptive Capitalising convention –InterestRate, InitialCapital
Variables Local –Declared within a subprogram –Dim varName As dataType Global –Declared at the top of the code listing –Private varName As dataType
Data Types
The ASCII Character Set Hex ABCDEF Binary BSHTLF CR ESC !"#$%&'()*+,-./ :;<=>? PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~DEL
Data Storage =255
Data Storage (2nd byte) = The largest Unsigned value that can be stored in 16 bits. How many different patterns?
Integer Storage To store integers, half the combinations are used to represent negative values. The range for Integer type variables is: -32,768 to The MSB is used to represent the sign. Which value of the sign bit (0 or 1) will represent a negative number?
2’s Complement Notation (examples in 8 bits to save space) The notation system that uses 1 to represent negative values. Fixed length notation system. Zero is the first non-negative value: The pattern immediately before zero is The largest value is stored as The smallest value is stored as
Arithmetic in 2’s Complement (remember it’s a fixed length system) = = = = 10 in 2’s complement in 2’s complement discard the carry bit
Long Integer Storage (4 bytes) High order bit (MSB) is worth 2 31 The number of different combinations =2 32 =4,294,967,296 Half are used for negative values, so the range is –2,147,483,648 to + 2,147,483,647
Fractions A radix separates the integer part from the fraction part of a number Columns to the right of the radix have negative powers of 2.
Fractions
Fractions ½¼⅛
Fractions ½¼⅛
Fractions ½¼⅛ ½+⅛
Fractions ½¼⅛ ½+⅛ 5⅝5⅝
Scientific Notation Very large and very small numbers are often represented such that their order of magnitude can be compared. The basic concept is an exponentional notation using powers of 10. a × 10 b Where b is an integer, and a is a real number such that: 1 ≤ |a| < 10
Scientific Notation An electron's mass is about kg. In scientific notation, this is written ×10 −31 kg. The Earth's mass is about 5,973,600,000,000,000,000,000,000 kg. In scientific notation, this is written ×10 24 kg.
E Notation To allow values like this to be expressed on calculators and early terminals × 10 b was replaced by Eb So ×10 −31 becomes E−31 And ×10 24 becomes E+24
E Notation The ‘a’ part of the number is called the mantissa or significand. The ‘Eb’ part is called the exponent. Since these numbers could also be negative they would typically have a sign as well.
Floating Point Storage In floating point the bit pattern is divided into 3 components: Sign – 1 bit (0 for +, 1 for -) Exponent – stored in Excess notation Mantissa – must begin with 1
Excess Notation (examples in 8 bits to save space) The notation system that uses 0 to represent negative values. Fixed length notation system. Zero is the first non-negative value: – The pattern immediately before zero is -1 – The largest value is stored as The smallest value is stored as
Mantissa Assumes a radix point immediately left of the first digit. The exponent will determine how far and in which directionto move the radix.
An example in 8 bits If the following pattern stores a floating point value, what is it?
An example in 8 bits If the following pattern stores a floating point value, what is it? Separate it into its components:
An example in 8 bits If the following pattern stores a floating point value, what is it? Separate it into its components: sign exponent mantissa
An example in 8 bits If the following pattern stores a floating point value, what is it? Separate it into its components: sign exponent mantissa
An example in 8 bits A sign bit of 0 means the number is…?
An example in 8 bits A sign bit of 0 means the number is positive. 110 in Excess Notation converts to …?
An example in 8 bits A sign bit of 0 means the number is positive. 110 in Excess Notation converts to +2. Place the radix in the mantissa …
An example in 8 bits A sign bit of 0 means the number is positive. 110 in Excess Notation converts to +2. Place the radix in the mantissa.1001 Put it all together …
An example in 8 bits A sign bit of 0 means the number is positive. 110 in Excess Notation converts to +2. Place the radix in the mantissa.1001 Put it all together … * 2 2
An example in 8 bits * 2 2 Multiplying a binary number by 2 shifts the bits left (move the radix to the right) one position. So the exponent tells us to shift the radix 2 positions right = 2¼
Normal Form The first bit of the mantissa must be 1 to prevent multiple representations of the same value. Otherwise…
Data Type Conversion