1.4.1 Data Types Flashcards

1
Q

What are the 5 primitive data types?

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is casting?

This is sometimes referred to as parsing

A

The process of changing one data type into another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a character set?

What are some examples?

A
  • A list of 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the ASCII character set

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe the UNICODE character set

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Left shift the following 8-bit number 3 places: 00111010

What mathematical operation is this equivalent to?

A

Remove the required number of bits from the left

Add the same number of zeros to the right

Answer = 11010000

Equivalent to multiplying the number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Right shift the following 8-bit number 3 places: 00111010

What mathematical operation is this equivalent to?

A

Remove the required number of bits from the right

Add the same number of zeros to the left

Answer = 00000111

Equivalent to dividing the number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Convert 177 to an unsigned 8-bit binary number

A
  • Use the binary number line (128 | 64 | 32 | 16 | 8 | 4 | 2 | 1)
  • 128+32+16+1 = 177

Answer = 10110001

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Convert the unsigned 8-bit binary number 10110010 to denary

A

Use the binary number line (128 | 64 | 32 | 16 | 8 | 4 | 2 | 1)

128+32+16+2 = 178

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Convert the denary number 188 to Hex

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Convert the hex FE to a denary number

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Convert -49 to an 8-bit binary number using two’s complement

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Convert 49 to an 8-bit binary number using two’s complement

A
  • No flipping required as it is a positive number
  • You only need to flip when it requires a negative number

Answer = 00110001

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Convert -49 to an 8-bit binary number using sign and magnitude

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Add the following two binary numbers

01101010 + 00111111

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Subtract the following two binary numbers

00101111 - 00010111

A
  • 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

17
Q

Mask 11010101 using the AND mask 10101010

A
  • Stack the two binary numbers on top of each other
  • Going from right to left - apply the rules of an AND gate

Answer = 10000000

18
Q

Mask 11010101 using the OR mask 10101010

A
  • Stack the two binary numbers on top of each other
  • Going from right to left - apply the rules of an OR gate

Answer = 11111111

19
Q

Mask 11010101 using the XOR mask 10101010

A
  • Stack the two binary numbers on top of each other
  • Going from right to left - apply the rules of an XOR gate

Answer = 01111111

20
Q

Normalise 0001011000 001100

A
  • 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

21
Q

Normalise
1110011000 001100

A
  • 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

22
Q

Convert 5.25 to an 6-bit mantissa and 3-bit exponent

A
  • 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

23
Q

Convert -5.25 to an 6-bit mantissa and 3-bit exponent

A
  • 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

24
Q

Convert 01110 0001 to floating point denary

A
  • 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

25
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** ## Footnote Alternative methods are available
26
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** ## Footnote **Any number less than 0.5 would have a negative exponent**
27
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** ## Footnote Alternative methods are available
28
**Add** the following floating point binary numbers stored in the two's complement format. **0110 0010 and 0100 0011**
* Calculate the exponent of the first number (0010 = 2) * Write out the first number with the binary point - Initially it will be before the left-most one - float it the required number of places dictated by the exponent (011.0) * Calculate the exponent of the second number (0011 = 3) * Calculate the second number - float it the required places (0100.0) * Stack the two numbers on top of each other and align the binary points * Perform binary addition from right to left (0111.00) * Using the set number of bits, write out the mantissa without its point (0111) * In binary write out how far you moved the binary point. Pad to the left to get it to the correct number of bits (3 = 0011) **Answer = 0111 0011** ## Footnote Always check your answer by converting both numbers to denary and doing the normal addition (3 + 4 = 7)
29
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
30
**Subtract** the following floating point binary numbers stored in the two's complement format. 010010 0100 - 010010 0010
* Calculate the exponent of the first number (0100 = 4) * Write out the first number with the binary point - Initially it will be before the left-most one - float it the required number of places dictated by the exponent (01001.0) * Calculate the exponent of the second number (0010 = 2) * Calculate the second number - float it the required places (010.010) * Flip and add one to the second number (101.110) * Stack the two numbers on top of each other and align the binary points - pad the negative number on the left with 1's if required. * Perform binary addition from right to left (0110.110 - you will get an overflow) * Using the set number of bits, write out the mantissa without its point (0111) * In binary write out how far you moved the binary point. Pad to the left to get it to the correct number of bits (3 = 0011) **Answer = 0110110 0011** ## Footnote Always check your answer by converting both numbers to denary and doing the normal subtraction (9 - 2.25 = 6.75)
31
What impact does **increasing** the size of the **exponent** have?
Increases the size of the number that can be stored.
32
What impact does **increasing** the size of the **mantissa** have?
Increases the precision of the number that can be stored.