1.4.1 Data types Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is static typing?

A

When variables have to be defined as a certain data type before they can be used.

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

What is dynamic typing?

A

When variables do not have to be defined before they are used and can be defined when needed.

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

Name 4 different data types.

A

String, Boolean, Integer, Float/Real

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

What is strong typing?

A

When variables are locked into a set data type and will not work if used as different data types.

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

What is weak typing?

A

When variables are not locked to a certain data type and can be used as multiple data types.

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

What is a primitive data type?

A

A data type that is provided by a programming language.

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

Name 5 primitive data types.

A
Integer
String
Real / Float
Boolean
(Character)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we convert between denary and hexadecimal?

A

Denary to Hex:
Divide by 16 = First Number
Remainder = Second Number

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

How do we convert a number from hex to denary/

A

Multiply first number by 16.

Add on second number.

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

What are the numbers 10-15 represented by in hexadecimal?

A

A B C D E F

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

How do we convert a number from binary to hex?

A

Split in to nibbles
First nibble = first number
2nd nibble = second number
so on…

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

How do we convert from Hex to binary?

A

First number = first nibble
2nd number = second number
so on…
combine nibbles

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

Why is hexadecimal used?

A

Because they are easier to remember and write / type for humans

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

What are the rules for binary addition?

A

0 + 0 = 0
1 + 0 = 1
1 + 1 = 0 (carry 1)
1 + 1 + 1 = 1 (carry 1)

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

What is an overflow error?

A

When two binary numbers are added together and the new value exceeds the maximum number of bits allowed.

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

How do we represent negative numbers using sign and magnitude?

A

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

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

Using sign and magnitude, is this number positive or negative?

10010101

A

Negative

18
Q

Why is sign and magnitude not used?

A

Because it does not work with binary arithmetic.

19
Q

How do we represent negative numbers using two’s complement?

A

The most significant bit is a negative value.
e.g.
With 8 bits, the MSB will equal -128.

20
Q

What is the greatest number that can be represented with 8 two’s complement bits.

A

127

21
Q

How can we represent a negative denary number in binary using twos complement?

A

Work out positive equivalent of number in binary.
Flip all of the bits
Add 1.

22
Q

How can we convert from a negative binary number in twos complement to a denary number?

A

Flip all of the bits and add 1.

Convert to denary to find positive equivalent.

23
Q

How do we carry out binary subtraction using twos complement?

A

Number to subtract = negative and then add the numbers together using normal binary addition rules.

24
Q

What is fixed point binary?

A

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)

25
Q

What is floating point binary?

A

When we store a float in a format where the decimal point is not in a fixed location.

26
Q

Where must the decimal point be in a normalised floating point number?

A

Between the first and second leftmost bits.

27
Q

What will the first two leftmost bits of a positive, normalised, floating point binary number always be?

A

01

All the repeating 0s before mean the same as a singe 0

28
Q

What will the first two leftmost bits of a negative, normalised, floating point binary number always be?

A

10

All repeating 1s before mean the same as the single 1 here. -128 + 64 + 32 == -32

29
Q

How do we add/subtract decimal binary numbers?

A

Denormalise the numbers
Align the decimal points
Carry out binary addition / subtraction as normal
Normalise the result

30
Q

What is an underflow error?

A

When a number is too small to be represented in the allotted number of bits.

e.g. 0.00005 / 200

31
Q

What is a logical shift?

A

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

32
Q

What are logical shifts used for?

A

Examining the least significant but of a number.

33
Q

What is an arithmetic shift?

A

The same as a logical shift, but the sign bit must always remain the same.

34
Q

What effect does a left arithmetic shift have on a number?

A

Multiplies by 2

35
Q

What effect does a right arithmetic shift have on a number?

A

Divides by 2

36
Q

How would you multiply by a non multiple of 2 in binary?

A

Use a combination of shifts and addition.

37
Q

What is a circular shift?

A

When the value moved out to the carry bit in a shift is added onto the other end of the number.

38
Q

Why do we use circular shifts?

A

If we are performing shifts in multiple bytes.

E.g. two registers used to store a 16 bit integer.

39
Q

What is masking useful for?

A

Allowing the CPU to manipulate individual bits in the operand, check for values and either allow or block bits.

40
Q

What is the AND mask useful for?

A

Checking conditions stored in a binary value.

41
Q

What is the OR mask useful for?

A

Resetting individual bits in a binary value.

42
Q

What is the XOR mask useful for?

A

Checking that two bits are not the same.