1.4 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

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.

A
  1. 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.
  2. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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?

A
  1. To represent a positive number using two’s complement, the MSB must be 0. For a negative number, the MSB must be 1.
  2. 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.
  3. To find the negative equivalent of a positive number: flip the bits and add 1.
  4. Unsigned binary is positive only, while signed binary is positive or negative.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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.

A
  1. 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.
  2. Contiguous means all the data is stored together, one element after the other.
  3. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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?

A
  1. 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.
  2. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

1.4.1
1) What are the case conversion commands?
2) What are the ASCII conversion commands?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

1.4.1
1) How does the binary number line method work?
2) How can you convert from binary to denary?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

1.4.1
1) How to convert from denary to hex?
2) How to convert from hex to denary?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

1.4.1
1) What is the MSB?
2) What is the LSB?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. What is a parameter?
  2. What is an argument?
A
  1. Parameters are the names of the information that is used in a function or procedure (eg. In function add(number), number is the parameter).
  2. An argument is a value that is passed into a function or procedure, (eg. add(3)).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. What is branching?
  2. What is switch and case?
A
  1. Branching is where a certain block of code is run ​if a specific condition is met​, using IF statements, also known as selection.
  2. 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. What is a data structure?
  2. What is a data type?
  3. What is an array?
A
  1. Data structure: a way of storing and managing data.
  2. Data type: a classification that specifies which type of value a variable has.
  3. Array: a set of data items of the same data type grouped together using a single identifier.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

1.4.3 Boolean Algebra
1. What is an AND and NOT logic gate?
2. What is an OR and XOR logic gate?

A
  1. 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.
  2. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. What is the OCR notation for the AND, NOT, OR and XOR gates?
  2. How do you construct boolean expressions?
A
  1. 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.
  2. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

1.4.1
1. What is fixed point representation?
2. What is normalised floating point representation?
3. What is a mantissa?

A
  1. 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.
  2. A representation of real numbers that stores a value for the mantissa and the exponent in two’s complement.
  3. The part of the floating point number that represents the significant digits of that number.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

1.4.1
1. What is an exponent?
2. What is normalisation?

A
  1. The power to which the number in the mantissa is to be raised.
  2. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is normalisation?

A

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.

17
Q

How do you normalise a floating point number?

A

First, work out what the exponent is and convert the number back to ordinary form. If the exponent is positive, the point moves to the right. If negative, the point moves to the left. Then convert to normalised floating point. A normalised positive mantissa starts at 0.1 and a normalised negative one starts at 1.0. Finally, check your answer. If you move the binary point as indicated by the exponent, you should get the ordinary form binary value.

18
Q

1.4.2
1. What are records?
2. How do you access each field in a record?

A
  1. Records are a group or collection of related fields under a single identifier. Each field (variable) can have a different data type (unlike arrays). They are used in conjunction with arrays or lists.
  2. To access each field in a record, you use a dot notation, eg. Harry.studentNumber = 3456
19
Q

1.4.2
1. What are lists?
2. What are tuples?
3. What is the difference between a list and an array.

A
  1. Lists are a collection of data items in a sequence without any gaps. They can be accessed via index, starting at 0. Data items can be inserted or deleted at any point in the list. It can hold different data types. Lists are dynamic (not fixed), and can grow and shrink as required.
  2. Tuples are immutable lists that cannot be changed (size or contents) during processing. They can have different data types.
  3. A list is changeable, can store more than one datatype, and the length of the list can change. An array is changeable, but can only store one datatype, and the length of the array cannot be changed.
20
Q

1.4.2
1. What are records?
2. How do you access each field in a record?

A
  1. Records are a group or collection of related fields under a single identifier. Each field (variable) can have a different data type (unlike arrays). They are used in conjunction with arrays or lists.
  2. To access each field in a record, you use a dot notation, eg. Harry.studentNumber = 3456
21
Q

What is the pseudocode for a binary search?

A

function binarySearch(list, item)
found = False
index = -1
start = 0
end = len(list - 1)
while start <= last and found = False
mid = round(start + end) / 2
if list[mid] = item then
found = True
index = mid
else
if list[mid] < item then
start = mid + 1
else
last = mid - 1
endif
endif
endwhile
return index
endfunction

22
Q

What the pseudocode for a linear search?

A

function linearSearch(list, item)
index = -1
i = 0
found = False
while i < len(list) and found = False
if list[i] = item then
index = i
found = True
endif
i = i + 1
endwhile
return index
endfunction

23
Q
  1. What is a binary search?
  2. What is a linear search?
A
  1. A binary search is an efficient algorithm for finding items in a sorted data set. It starts at the middle item of the list and repeatedly divides the list in half. A binary search is efficient for large data sets, but the data must be sorted first.
  2. A linear search is a method for finding an element within a list. It checks each element of the list in order until a match is found or the whole list has been searched
24
Q
  1. What is the difference between signed and unsigned binary?
  2. What is the difference between the sign and magnitude and two’s complement approach for representing signed numbers in binary?
A
  1. Unsigned binary is positive only, while signed binary is positive or negative.
  2. 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. Logical but not used due to processing issues. Eg. 00000000 - positive zero, 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 - 0000. 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.
25
Q

1.4.2
1. What is a record?
2. How do you use a record?

A
  1. A record is a collection of related fields. A field is a variable, and each field in a record can have a different data type.
  2. To use a record: first you define the field names and the data types that they store. Then, you define the variable that you will use and assign the variable to the record name. Finally, you assign a value to each field name within the record.
26
Q

1.4.2
1. What are tuples?
2. What is the difference between a list or array?

A
  1. Tuples are lists that cannot be changed, but can store multiple store multiple different data types.
  2. A list is changeable, and can store more than one data type. Whereas, an array is not changeable, and can only store one data type.