1.4.1 Data Types Flashcards
What are the 5 primitive data types?
- Real / Floating Point – Stores decimal numbers (3.141)
- Character - A single letter, number or special character (‘H’)
- String – A collection of characters (“Hello World”)
- Boolean – TRUE or FALSE
- Integer – A positive or negative whole number (24, -34)
What is casting?
This is sometimes referred to as parsing
The process of changing one data type into another.
What is a character set?
What are some examples?
- List of all the characters the computer can represent.
- Each character is represented by a unique binary value.
- Used to map binary values to characters.
- Examples: UNICODE and ASCII
Describe the ASCII character set
- ASCII is a character set which is a subset of UNICODE
- Uses 7 bits, or 8 bits for extended ASCII
- Fewer characters can be represented than UNICODE
- Characters from different languages cannot be represented in ASCII
Describe the UNICODE character set
- Each character is represented by 1-4 bytes.
- It supports a very large number of characters
- It is backwards compatible with ASCII
- Text using UNICODE rather than ASCII would take up more storage (roughly 4 times more)
Convert 177 to an unsigned 8-bit binary number
- Use the binary number line (128 | 64 | 32 | 16 | 8 | 4 | 2 | 1)
- 128+32+16+1 = 177
Answer = 10110001
Convert the unsigned 8-bit binary number 10110010 to denary
Use the binary number line (128 | 64 | 32 | 16 | 8 | 4 | 2 | 1)
128+32+16+2 = 178
Convert the denary number 188 to Hex
- Binary = 010111100
- Split from right to left into nibbles = 1011 1100
- Convert to denary using 8421 number line for each nibble
- 1011 = 11 | 1100 = 12
- Remember A = 10 | F = 15
Answer = BC
Convert the hex FE to a denary number
- Remember A = 10 | F = 15
- F = 15 | E = 14
- Write each character in a 4-bit nibble = 1111 1110
- Combine into one binary number = 11111110
- Convert to denary = 128+64+32+16+8+4+2
Answer = 254
Convert -49 to an 8-bit binary number using two’s complement
- Write out the positive version of 49 in binary = 00110001
- Flip and add one to the bits (2’s Complement) = 11001111
Answer = 11001111
Alternative methods exist using (-128) + 64 + 8 + 4 + 2 + 1 = -49
Convert 49 to an 8-bit binary number using two’s complement
- No flipping required as it is a positive number
- You only need to flip when it requires a negative number
Answer = 00110001
Convert -49 to an 8-bit binary number using sign and magnitude
- Your left-most bit (most significant) is now only available to store a 1 for negative OR 0 for positive.
- Use the remaining bits to make the number (-) 0110001
Answer = 10110001
Add the following two binary numbers
01101010 + 00111111
Stack the numbers on top of each other and use the rules of binary addition going from right to left
- 0 + 0 = 0
- 1 + 0 = 1
- 1 + 1 = 0 (carry 1)
- 1 + 1 + 1 = 1 (carry 1)
01101010
00111111 +
Answer = 10101001
Carries - 11111100
Subtract the following two binary numbers
00101111 - 00010111
- Convert the second number to a negative version (flip+add 1)
- Stack the original first number on top of the new negative second number
- Follow the rules of binary addition
Answer = 00011000
An overflow should always occur using this method
An alternative borrowing method is also suitable
Normalise
0001011000 001100
- A normalised number can only start with 01 if positive, or 10 if it is negative
- Remove the excess bits from the front of the number - be careful not to change the sign of the number. (01011000)
- For each digit removed - pad the right of the mantissa with 0s (0101100000)
- Convert the original exponent to denary and subtract the number of number bits that you removed from the front of the mantissa (12-2)
- Convert the exponent back to binary (it could be a negative number)
Answer = 0101100000 001010
(Remove the two extra bits from the front of the mantissa and reduce the exponent value by 2)
Alternative methods are available
Normalise
1110011000 001100
- A normalised number can only start with 01 if positive, or 10 if it is negative
- Remove the excess bits from the front of the number - be careful not to change the sign of the number (10011000)
- For each digit removed - pad the right of the mantissa with 0s (1001100000)
- Convert the original exponent to denary and subtract the number of number bits that you removed from the front of the mantissa (12-2)
- Convert the exponent back to binary (it could be a negative number)
Answer = 1001100000 001010
(Remove the two extra bits from the front of the mantissa and reduce the exponent value by 2)
Alternative methods are available
Convert 5.25 to an 6-bit mantissa and 3-bit exponent
- Write out the number in fixed point binary (0101.01)
- Float the binary point to be to the left of the first 1 (0.10101)
- Write out the number without the binary point (010101) - this is your mantissa. If it is not long enough then pad on the right with zeros.
- In binary, write out how many places you floated the binary point (011) this is your exponent. If it is not long enough then pad on the left with zeros.
Answer = 010101 011
Alternative methods are available
Convert -5.25 to an 6-bit mantissa and 3-bit exponent
- Write out the number in fixed point binary (0101.01)
- Float the binary point to be to the left of the first 1 (0.10101)
- Write out the number without the binary point (010101) - this is your mantissa. If it is not long enough then pad on the right with zeros.
- In binary, write out how many places you floated the binary point (011) this is your exponent. If it is not long enough then pad on the left with zeros.
- We need the mantissa to be negative - so flip and add one to the bits.
Answer = 101011 011
Alternative methods are available
Convert 01110 0001 to floating point denary
- Convert the exponent (0001) to denary (Exp = 1)
- If the mantissa is negative then flip and add one to it.
- Add the binary point to the left of the first 1 in the mantissa (0.1110)
- Float the binary point as dictated by the exponent - Right if negative exponent OR left if positive exponent (01.110 in fixed point).
- Calculate the denary value - normal binary to the left of the binary point and fractions to the right of it (1/2 | 1/4 | 1/8 | 1/16)
Answer = 1.75
Alternative methods are available
Convert 10010 0001 to floating point denary
- Convert the exponent (0001) to denary (Exp = 1)
- If the mantissa is negative then flip and add one to it (01110)
- Add the binary point to the left of the first 1 in the mantissa (0.1110)
- Float the binary point as dictated by the exponent - Right if negative exponent OR left if positive exponent (01.110 in fixed point).
- Calculate the denary value - normal binary to the left of the binary point and fractions to the right of it (1/2 | 1/4 | 1/8 | 1/16)
Answer = -1.75
Alternative methods are available
Convert 0.125 to an 6-bit mantissa and 3-bit exponent
- Write out the number in fixed point (0.0010) - 1/8
- Calculate how many places the binary point needs to float to be to the left of the left-most one (2 places to the right, this is a negative movement)
- Remove the additional zeros from the front of the mantissa to get it to be 01 for positive or 10 for negative.
- Pad the mantissa on the right hand side to make it to the required number of bits (010000)
- Write out your exponent 010 - flip to be negative 110
Answer = 010000 110
Any number less than 0.5 would have a negative exponent
Convert -0.125 to an 6-bit mantissa and 3-bit exponent
- Ignore the negative - write out the number in fixed point (0.0010) - 1/8
- Calculate how many places the binary point needs to float to be to the left of the left-most one (2 places to the right, this is a negative movement)
- Remove the additional zeros from the front of the mantissa to get it to be 01 for positive or 10 for negative.
- Pad the mantissa on the right hand side to make it to the required number of bits (010000)
- Flip and add one to the mantissa to make it negative.
- Write out your exponent 010 - flip to be negative 110
Answer = 110000 110
Alternative methods are available
Why do we normalise floating point numbers?
Allows for more accuracy/precision from the given number of bits
So that the representation of each binary value is unique
What impact does increasing the size of the exponent have?
Increases the size of the number that can be stored.
What impact does increasing the size of the mantissa have?
Increases the precision of the number that can be stored.