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

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
7
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
8
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
9
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
10
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
11
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
12
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
13
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
14
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

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

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

17
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

18
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

19
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

20
Q

Convert 10010 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 (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

21
Q

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

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

22
Q

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

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

23
Q

Why do we normalise floating point numbers?

A

Allows for more accuracy/precision from the given number of bits

So that the representation of each binary value is unique

24
Q

What impact does increasing the size of the exponent have?

A

Increases the size of the number that can be stored.

25
Q

What impact does increasing the size of the mantissa have?

A

Increases the precision of the number that can be stored.