[Unit 1.4.1] Data Types Flashcards
data types
define data type
nature of data a variable can hold
what do data types specify
kind of values that can be stored
what operations can be performed on them
how data is stored in memory
why are data types important
error prevention
efficient memory use
performance optimisation
code clarity and maintainability
what is the difference between data types and data structures
types - low level and intrinsic to variables
structures - high level and organise multiple variables
define character code
unique binary sequence represent a single letter
define character set
standardised collection of characters and their codes to represent them
what is ASCII
American Standard Code for Information Interchange
originally used 7 bits. 128 combinations (0-127)
what is extended ASCII
8 bits, 256 characters (0-255)
-additions were non-standard and varied between countries
what are the disadvantages of ASCII
-256 values is not enough to represent all symbols for all languages of the world
-people made systems which were not compatible with each other
define Unicode
Unicode is a standard character set that is backwards compatible with ASCII. uses 32 bits. standard across all systems
features of a Array
Fixed size
Items can change
Can store only one data type
features of a List
Can change size
Items can change
Can store more than one data type
features of a Tuple
Fixed size
Items can’t change
Can store multiple data types
what are unsigned values
integers have positive values
what are signed values
integers can be positive or negative
how does “sign and magnitude” work
uses MSB to determine if value is negative or positive
0 is positive
1 is negative
what are the disadvantages to sign and magnitude
halves the highest value we can represent
complicates arithmetic
how does twos complement work
MSB is a negative value (e.g in 8 bits the MSB would become -128)
thus:
0 is positive
1 is negative
how do you convert from regular binary to twos complement (+ -> -)
write out the positive value
flip all the bits to the left of LSB (keep LSB same)
what values can you represent in 8 bits using sign and magnitude
-127 to 127
what values can you represent in 8 bits using twos complement
-128 to 127
what are the rules for binary addition
0+0 = 0
0+1 = 1
1+1 = 0 (carry 1)
1+1+1 = 1 (carry 1)
what are the rules for binary subtraction
0-0 = 0
0-1 = 1 (flip 0s till you get to 1)
1-0 = 1
1-1 = 0
how can you do binary subtraction using twos complement
17-14 is the same as 17+(-14)
so switch 14 into twos complement
and do binary addition
ignore overflow
what is bitwise manipulation
modifying data by changing bits within byte
what does a shift to the left do
multiplies by 2
what does a shift to the right do
divides by 2
how can you multiply by 6 on a binary number
first multiply original value by 2
then multiply original value by 4
add these two values together
how do you do arithmetic shift
same as binary shift just keep the MSB the same
what is the logical operator for AND
2 inputs, a D, one output.
both values must be true
what is the logical operator for OR
2 inputs, spaceship, one output, either or both values must be true
what is the logical operator for XOR
2 inputs, ), spaceship, one output, either but not both values must be true
what is bit masking
keep, change or remove desired part of information by imposing a mask over its bits
what are the 3 masks for bit masks in terms of bitwise manipulation
AND to extract
OR to set
XOR to toggle
what is fixed point form
binary point in fixed position. does not need to be stored in memory
what is floating point form
using mantissa and exponent.
what is the function of the mantissa in floating point form
main number containing point after MSB
what is the function of the exponent in floating point form
where binary point is positioned. if exponent is negative point goes left. if it is positive it goes right.
what happens if you increase the amount of bits for the mantissa
increase in accuracy
what happens if you increase the amount of bits for the exponent
increase in range
define “normalisation”
moving binary point of decimal number
why do we normalise numbers
to maximise accuracy and range for given number of bits
how do you tell if a number is normalised
positive would start 01
negative would start 10
how do you normalise a floating point
adjust exponent
-move right (increase mantissa) decrease exponent
-move left (decrease mantissa) increase exponent
how do you convert from denary to floating point
write it in fixed point first in twos comp
normalise
write out fully
how do you do addition/subtraction of floating point
normalise both numbers
make exponents equal (smaller->larger)
perform calculation
normalise result