DATA TYPES Binary • Computers store data as binary using switches (on/off maps to 1/0 • Can represent numbers, text (using ASCII or Unicode), images (pixels) or sound • Sign and magnitude or two's complement to represent negative numbers • Subtraction - convert to two's complement and add Hexadecimal • More visually compact • Easier for humans to read and remember • Easy to convert from binary and vice versa (4 bits = 1 hex digit) • Uses ○ Colour codes e.g. #FF5733 ○ Memory addresses ○ Mac addresses Floating-point binary • Purpose of normalisation ○ Ensures maximum precision e.g. mantissa of 0.001011101 is stored as 0.00101 unnormalised with a 5 bit mantissa but 0.10111 normalised ○ Ensures each number has a unique representation so they can be compared easily Logical shifts • Logical shift left - pad with 0, multiplies number by 2 • Logical shift right - pad with 0, divides number by 2 Bitwise operators and masks • AND - used to set specific bits to 0 • OR - used to set specific bits to 1 • XOR - used to toggle specific bits Character sets • A character set is a standard list of characters with a unique binary number assigned to each • Ensures that computers store and interpret text consistently and allows different devices to communicate clearly • ASCII uses 7 bits so can store 27 = 128 characters • Unicode uses more bits so can store far more characters, allowing it to store characters from different languages, symbols, and emojis DATA STRUCTURES Arrays, records, lists and tuples • A data structure is an ordered collection of items under a single identifier • Arrays ○ Static (fixed-length), mutable (items can change), can only store one data type ○ Stored in contiguous memory - CPU can move through them really quickly ○ Static - memory straight after it can be allocated to something else • Records ○ Mutable, static ○ Store different types of data about one thing ○ Like a database table row, with each different item being a field ○ Each field can only store data of one type, but different fields can store different data types • Tuples ○ Immutable, static, can store different data types ○ Used when data needs to be kept constant ○ Static - memory straight after it can be allocated to something else • Lists ○ Mutable, dynamic (length can change) and can store different data types ○ Storage required is unknown initially - less memory efficient ○ Often requires extra memory for pointers ○ More difficult to program BOOLEAN ALGEBRA