[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