click below
click below
Normal Size Small Size show me how
1.4.1
| Question | Answer |
|---|---|
| Primitive Data Types | any basic data type provided by a language as a building block Variables have a data type as well as a value, to tell the compiler/interpreter how that data is going to be used and stored |
| Casting | a way to convert one data type to another. str(), int(), float() |
| Integer (Primitive Data Types) | a whole number |
| Real/floating point (Primitive Data Types) | numbers with decimal or fractional parts |
| Character (Primitive Data Types) | (char): single letter, number, symbol or control character like NULL |
| String (Primitive Data Types) | a series of characters |
| Boolean (Primitive Data Types) | one of two values (true or false, 1 or 0) |
| Denary | Humans use denary (base 10) |
| Binary | Computers use binary (base 2): Uses 0 and 1 - 1 represents the presence of an electrical signal - 0 represents the absence |
| Binary to denary | |
| Denary to binary | |
| 2 methods of negative binary | - Sign-and-Magnitude - Two's complement |
| Sign-and-magnitude (negative binary) | The MSB indicates the sign: (in the column heading, write +/- (sign bit)) - 0 = + - 1 = - The rest is the magnitude (number itself), represented as normal |
| Two's complement (negative binary) | MSB is a negative number (e.g. -128) Negative numbers start with 1, positive with 0 E.g. -117 = 10001011 (-128 + 8 + 2 + 1 |
| positive binary to two's complement | 1. Write out positive number (with the MSB being negative) 2. Start from LSB and them exactly up to and including the first 1 3. After that, swap every 1 for a 0 and 0 for a 1 |
| Adding binary | Same for two's complement Column addition, the 4 possibilities: 0 + 0 = 0 1 + 0 = 1 1 + 1 = 0 (carry 1) 1 + 1 + 1 = 1 (carry 1) Too work things out: 1 + 1 + 1 = 3, written as 11 in binary Always show carries |
| Overflow error | When there are more bits in an answer then expected, data will be lost and the answer will be wrong |
| Subtract binary | Turn the number we want to subtract (second number) into two's complement Add the two numbers together Remove the first number |
| Hexdecimal | (base-16) Not used by computers but: - Easy to convert to binary as 1 digit = 1 nibble (4 binary digits), - Easier to interpret by humans - Digits 0-9 and A-F - Each place value increases by a power of 16 |
| Denary to hex | go through binary |
| Hex to denary | go through binary |
| Binary to hex | Split the number into nibbles Convert each nibble into a number and translate to the hex equivalent Merge the letters in the same order as the nibbles (not add) 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F |
| Hex to binary | Convert each digit into a binary nibble Merge the nibbles (not add) |
| Floating point binary | The number line goes -16 8 4 2 1 ½ ¼ ⅛ (half as move to right) - Fixed point - Floating point |
| Fixed point (floating point binary) | the position of the point doesn’t move - Binary point between 1 and ½ - 6.5 = 00011110 - -6.5 = 11001100 - Limited numbers (⅓ can’t be shown) |
| Floating point (floating point binary) | allows binary point to move (like standard form) (atsta after mantissa MSB) Either increase: -Size (more whole number parts) -Accuracy (more fractional parts) Parts: -Mantissa -Exponent |
| Mantissa | The number itself - Binary point after the MSB - Two’s complement - MSB = -1 |
| Exponent | The position of binary point in number (like the power) - Two’s complement |
| Binary to denary (floating point binary) | 1. Convert exponent 2. Move binary point a number of places based on the exponent - Right if positive - Left if negative 3. Change column headings so binary point is after 1 - It is in two’s complement 4. Convert the mantissa to get the number |
| Normalisation (floating point binary) | Stops different ways of representing one number Stores numbers with the highest possible degree of accuracy - Positive mantissas start w/ 01 (negative w/ 10) |
| Normalisation steps(floating point binary) | 1. Float the mantissa until it is correct 2. Set the exponent to the amount of places moved - If you moved to the left, positive exponent - If you moved to the right, negative exponent |
| Denary to binary (floating point binary) | 1. Write the number as a fixed-point number - If it is a negative number, write it in two’s complement 2. Float the binary point so the number is normalised 3. Create the exponent; amount of spaces floated 4. Write out the numbers as the mantissa |
| Addition (floating point binary) | Use the exponent to find out the number Add numbers up normally (fill any spaces up) |
| Subtraction | Use the exponent to find out the number Subtract numbers normally (fill any spaces up) |
| Bitwise manipulation | - Logical shifts - Masking |
| Logical shifts (Bitwise manipulation) | moves all bits to a certain way: - Left shift multiplies by 2 - Right shift halves - Remaining space padded by 0 - Shifts too far may result in loss of precision or overflow |
| Masking (Bitwise manipulation) | Allows us to isolate and extract bit values from a sequence Allows us to toggle and set bit values in a sequence of bits Use logical operators (AND, OR, XOR) |
| AND (Bitwise manipulation) | extract a subset of bits Where the mask is 1, we are copying the original number Where the mask is 0, we are blanking/ignoring original number |
| OR (Bitwise manipulation) | OR (sets a subset of bits) Where the mask is 1, we have set the values to 1 Where the mask is 0, we are copying the original number |
| XOR (Bitwise manipulation) | XOR (exclusive or) (toggle a subset of bits) Where the mask is 1, we are toggling/switching the numbers Where the mask is 0, we are copying the original number |
| Character set | a defined list of characters recognised by the computer hardware and software, with each character being represented by a binary number It is important that every device uses the same binary number to represent each character so that they can communicate |
| Agreed character sets | There are agreed international standards used: - ASCII - Unicode |
| ASCII | american standard code for information interchange): - English alphabet, numbers, punctuation and non-printable control codes - 7 bits per character, allowing (2^7 = ) 28 characters |
| Extended ASCII | uses 8 bits for (2^8 = )256 characters, and included foreign languages and some graphic symbols |
| ASCII pros and cons | Pros - Storage efficient - Little bandwidth Cons - Less characters - Not for global communication |
| Unicode | universal encoding - Characters from every writen language, historical scripts, emojis - 16 bits per character, 65536 characters - Later variants use 24 bits, allowing over 16 million characters, and hex is often used when writing out the codes |
| UTF8 variant (Unicode) | compatible with ASCII as first characters are the same |
| Unicode pros and cons | Pros - Many characters - Unifies different character sets Cons - More bandwidth required - More storage space |