1.4 Flashcards
1.4.1: Signed Binary
What is the difference between the sign and magnitude approach and two’s complement approach for representing signed numbers in binary.
- Approach 1: Sign and Magnitude
MSB (the left bit) is used to represent the sign with 0 = +ve, 1 = -ve. To store a negative version of a number, you just set the MSB to 1.
It is logical but not used due to processing issues including two zeros, eg. 00000000 - positive 0, 10000000 - negative zero. - Approach 2: Two’s Complement
To change from denary to two’s complement, first flip all of the binary digits, then add the binary digit 1. To convert from two’s complement to denary, flip the binary digits and subtract binary 1.
There is only one zero - 00000000, but there is an imbalance in the range: -8 to +7 for a nibble. You can do normal addition but it could lead to an overflow error.
1.4.1
1. How to represent signed integers using two’s complement?
2. How to convert from binary two’s complement to denary?
3. How do you find the negative equivalent of a positive number?
4. What is the difference between unsigned and signed binary?
- To represent a positive number using two’s complement, the MSB must be 0. For a negative number, the MSB must be 1.
- To convert from binary to two’s complement to denary, you can simply add up the denary place values. If the MSB is 1, subtract 128.
- To find the negative equivalent of a positive number: flip the bits and add 1.
- Unsigned binary is positive only, while signed binary is positive or negative.
1.4.2: Data Structures - Arrays up to 2 dimensions
1. What is an array?
2. What does contiguous mean?
3. Explain the properties of an array.
- An array is a variable which can store more than one data item. This is done by allocating a contiguous part of memory for the purpose of storing that data.
- Contiguous means all the data is stored together, one element after the other.
- Arrays are a static data structure, so you can’t change the size of an array once you have set it up. Items in an array start at index zero. Arrays usually only support one data type.
1.4.1: Signed integers in binary
1. How do you convert from denary to binary two’s complement?
2. How do you add and subtract integers represented in two’s complement?
- Converting from denary to binary two’s complement: positive numbers are the same as in unsigned binary. For negative numbers: first write the positive version, then flip the digits and add 1.
- To add integers represented in two’s complement, you do it the same as you would with unsigned binary. However, an overflow error may result in the wrong number as the answer.
To subtract integers using two’s complement: subtracting a number from the other is the same as adding to the negative version of the number. Eg, 93-34 = 93 + (-34). So convert the number you are subtracting into a negative binary, then add.
1.4.1
1) What are the case conversion commands?
2) What are the ASCII conversion commands?
1) String.upper : Returns the string in upper case.
String.lower : Returns the string in lower case.
String.isUpper : Returns True, if all the characters are upper case.
String.isLower : Returns True, if all the characters are lower case.
1.4.1
1) How does the binary number line method work?
2) How can you convert from binary to denary?
1) Binary number line method: Write out the binary number line, consider whether the number you want to store is more than or equal to the value in the column heading. If it is, write a 1 and reduced and number by the amount.
2) Convert from binary to denary: Write out in binary number line binary digits underneath. Add up the denary of the columns with a number 1.
1.4.1
1) How to convert from denary to hex?
2) How to convert from hex to denary?
1) How to convert between denary and 2 digit hexadecimal: First convert from denary to binary. Then, group the nibbles and find the number 1-16 that the two nibbles represent, and convert this into two hex digits.
2) How to convert between hex and denary: Convert each hex digits into two binary nibbles. Then, convert the binary into denary.
1.4.1
1) What is the MSB?
2) What is the LSB?
1) The most significant bit (MSB) is the left most bit, representing the largest value.
2) The least significant bit (LSB) is the right most bit, representing the least value.
- What is a parameter?
- What is an argument?
- Parameters are the names of the information that is used in a function or procedure (eg. In function add(number), number is the parameter).
- An argument is a value that is passed into a function or procedure, (eg. add(3)).
- What is branching?
- What is switch and case?
- Branching is where a certain block of code is run if a specific condition is met, using IF statements, also known as selection.
- Switch and case is comparing the same variable to multiple different conditions, and running the code if the conditions are met.
Example:
Switch Number
Case 1: print(‘First’)
Case 2: print(‘Second’)
Case 3: print(‘Third’)
default: print(‘Number not recognised’)
End Switch
- What is a data structure?
- What is a data type?
- What is an array?
- Data structure: a way of storing and managing data.
- Data type: a classification that specifies which type of value a variable has.
- Array: a set of data items of the same data type grouped together using a single identifier.
1.4.3 Boolean Algebra
1. What is an AND and NOT logic gate?
2. What is an OR and XOR logic gate?
- A NOT gate reverses the input. If the input A is 0/FALSE/OFF, then the output is 1/TRUE/ON. The symbol is a triangle with a circle at the point.
An AND gate output is TRUE if both of its inputs are TRUE – otherwise, the output is FALSE. If input A is 0 and B is 0, then the output is 0. The symbol looks like the letter D. - An OR gate output is TRUE if at least one of its inputs is TRUE – otherwise, the output is FALSE. If input A is 0, and B is 0, then the output is 0. The symbol is a curved arrow head that looks like a shield, with the two inputs going through the curved end
An XOR gate is TRUE if one and only one of its inputs is TRUE – otherwise, the output is FALSE. If input A is 0 and B is 0, then the output is 0. The symbol is a curved arrow head that looks like a shield, with an extra curved line close to the input side.
- What is the OCR notation for the AND, NOT, OR and XOR gates?
- How do you construct boolean expressions?
- The OCR notation for the AND gate is an upside down capital letter V.
The OCR notation for the NOT gate is a long horizontal line with a short vertical line to the right.
The OCR notation for the OR gate is a capital letter V.
The OCR notation for the XOR gate is a capital letter V with a horizontal line touching the bottom. - To construct boolean expressions, you need the letter for the final output, then =, then all the expressions for the inputs using OCR notation. For logic gates with multiple inputs, you use brackets around them to make it clearer.
1.4.1
1. What is fixed point representation?
2. What is normalised floating point representation?
3. What is a mantissa?
- A representation of real numbers that uses a defined number of bits for the whole number part and a defined number of bits for the fractional part.
- A representation of real numbers that stores a value for the mantissa and the exponent in two’s complement.
- The part of the floating point number that represents the significant digits of that number.
1.4.1
1. What is an exponent?
2. What is normalisation?
- The power to which the number in the mantissa is to be raised.
- Normalisation is the process of moving the binary point of a floating point number to provide the maximum range or level of precision for a given number of bits.