1.4.1 Data types Flashcards
What is static typing?
When variables have to be defined as a certain data type before they can be used.
What is dynamic typing?
When variables do not have to be defined before they are used and can be defined when needed.
Name 4 different data types.
String, Boolean, Integer, Float/Real
What is strong typing?
When variables are locked into a set data type and will not work if used as different data types.
What is weak typing?
When variables are not locked to a certain data type and can be used as multiple data types.
What is a primitive data type?
A data type that is provided by a programming language.
Name 5 primitive data types.
Integer String Real / Float Boolean (Character)
How do we convert between denary and hexadecimal?
Denary to Hex:
Divide by 16 = First Number
Remainder = Second Number
How do we convert a number from hex to denary/
Multiply first number by 16.
Add on second number.
What are the numbers 10-15 represented by in hexadecimal?
A B C D E F
How do we convert a number from binary to hex?
Split in to nibbles
First nibble = first number
2nd nibble = second number
so on…
How do we convert from Hex to binary?
First number = first nibble
2nd number = second number
so on…
combine nibbles
Why is hexadecimal used?
Because they are easier to remember and write / type for humans
What are the rules for binary addition?
0 + 0 = 0
1 + 0 = 1
1 + 1 = 0 (carry 1)
1 + 1 + 1 = 1 (carry 1)
What is an overflow error?
When two binary numbers are added together and the new value exceeds the maximum number of bits allowed.
How do we represent negative numbers using sign and magnitude?
We make the leftmost bit (the most significant bit) a sign bit.
If this is 0, the number is positive
If this is 1 the number is negative
Using sign and magnitude, is this number positive or negative?
10010101
Negative
Why is sign and magnitude not used?
Because it does not work with binary arithmetic.
How do we represent negative numbers using two’s complement?
The most significant bit is a negative value.
e.g.
With 8 bits, the MSB will equal -128.
What is the greatest number that can be represented with 8 two’s complement bits.
127
How can we represent a negative denary number in binary using twos complement?
Work out positive equivalent of number in binary.
Flip all of the bits
Add 1.
How can we convert from a negative binary number in twos complement to a denary number?
Flip all of the bits and add 1.
Convert to denary to find positive equivalent.
How do we carry out binary subtraction using twos complement?
Number to subtract = negative and then add the numbers together using normal binary addition rules.
What is fixed point binary?
When we determine how many numbers there will be before and after a decimal point, in order to hold floats.
e. g. 4 before and after
3. 75 = 0011 1100 (3) (0.75)
What is floating point binary?
When we store a float in a format where the decimal point is not in a fixed location.
Where must the decimal point be in a normalised floating point number?
Between the first and second leftmost bits.
What will the first two leftmost bits of a positive, normalised, floating point binary number always be?
01
All the repeating 0s before mean the same as a singe 0
What will the first two leftmost bits of a negative, normalised, floating point binary number always be?
10
All repeating 1s before mean the same as the single 1 here. -128 + 64 + 32 == -32
How do we add/subtract decimal binary numbers?
Denormalise the numbers
Align the decimal points
Carry out binary addition / subtraction as normal
Normalise the result
What is an underflow error?
When a number is too small to be represented in the allotted number of bits.
e.g. 0.00005 / 200
What is a logical shift?
When all the bits move left or right.
RHS: Least significant bit moves into carry bit and zero replaces most significant bit
LHS: Most significant bit moves into carry bit and zero replaces least significant bit
What are logical shifts used for?
Examining the least significant but of a number.
What is an arithmetic shift?
The same as a logical shift, but the sign bit must always remain the same.
What effect does a left arithmetic shift have on a number?
Multiplies by 2
What effect does a right arithmetic shift have on a number?
Divides by 2
How would you multiply by a non multiple of 2 in binary?
Use a combination of shifts and addition.
What is a circular shift?
When the value moved out to the carry bit in a shift is added onto the other end of the number.
Why do we use circular shifts?
If we are performing shifts in multiple bytes.
E.g. two registers used to store a 16 bit integer.
What is masking useful for?
Allowing the CPU to manipulate individual bits in the operand, check for values and either allow or block bits.
What is the AND mask useful for?
Checking conditions stored in a binary value.
What is the OR mask useful for?
Resetting individual bits in a binary value.
What is the XOR mask useful for?
Checking that two bits are not the same.