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 van simply add up the denary place values. If the 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 the 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.2
1. What is a record?
2. How do you use a record?
- A record is a collection of related fields of field is a variable in each field in the record can have a different data type.
- To use a record:
First you define the field names and the data types the store. Then, you declare the variables that you will use and the sign the variable to the record name. Finally, you assign a value to each fieldname within the record.
1.4.2
1. What are tuples?
2. What is the difference between a list and array?
- Tuples are lists that cannot be changed, but can store multiple different data types.
- A list is changeable, and can store more than one datatype. An array is changeable, but can only store one datatype.
1.4.1: Signed integers in binary
1. How do you find the negative equivalent of a positive number?
2. How do you convert from denary to binary two’s complement?
3. 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.
- An argument is a value that is passed into a function or procedure.
- 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.