1.4.1 - Data Types - Using binary Flashcards

1
Q

Primitive data types

A

One provided by a programming language

Integer, float, char, string, Boolean

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

Denary

A

Base 10/decimal

Our number system

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

How to know what data type a value is in

A

It will have 2/10/16 written in subscript

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

Binary

A

Uses 1/0 multiplied by the base, starting from the right

The bases are all powers of 2

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

Converting from denary to binary

A

Put a 1 in the column that is closest to the denary value, subtract and repeat

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

Hexadecimal

A

Uses base 16

Letters A-F represent values 10-15

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

Hexadecimal advantages

A

Quicker
Easier to understand
Less likely to make errors

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

Converting hex to denary

A

Show workings

Convert letters to digits, multiply by base and sum

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

Converting denary to hex

A

Divide by 16, add the hex symbol of the remainder assuming 2 bit value

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

Hex and binary conversions

A

Each hex value is 4 bits of binary
Convert the hex or binary to digit and then write out as the other
Combine the outputs

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

Binary addition

A

Works similar to denary, carry over a 1 if you have to go back to 0

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

What happens if adding 2 8-bit numbers gives a 9-bit answer?

A

There is an overflow error and the computer just cuts off the last bit from its output
Clearly indicate this in your answers

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

Range of Binary Addition

A

0 -> (2^n) -1 where n is the number of bits

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

Binary Subtraction

A

You make the second number into its negative value using Two’s Complement and then add them

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

Sign and Magnitude

A

The first bit represents +/- and then the rest are the same

The first bit being a 1 means the number is negative.

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

Two’s Complement Grid

A

The leftmost column has the negative value of itself

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

Sign and Magnitude Range

A

-(2^(n-1) + 1 -> (2^)n-1)) -1

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

Two’s Complement Process

A
  1. Find the positive value
  2. Invert the value of each bit
  3. Add one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Two’s complement range

A
  • (2^(n-1)) -> 2^(n-1) - 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What happens if there is overflow in binary subtraction?

A

You can ignore those bits

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

What are the lsb and msb

A

lsb - least significant bit - the rightmost bit

msb - most significant bit - the leftmost bit

22
Q

Logical shift left

A

Pushes every value 1 space to the left, the msb goes into the carry bit, 0 comes into the lsb

23
Q

Logical shift right

A

Pushes every value 1 space to the right, the lsb goes into the carry bit, 0 comes into the msb

24
Q

Logical shift sums

A

x2 for left, /2 for right as long as it isn’t two’s complement or sign and magnitude

25
Arithmetic shift left
Pushes every value 1 space to the left but the msb doesn't move so the second bit from the left goes into the carry bit, 0 comes in as lsb
26
Arithmetic shift right
Pushes every value 1 space to the right and the value that comes into the msb is whatever was there before
27
Arithmetic shift sums
x2 for left, /2 for right, for all numbers
28
Circular shift left
Pushes every value 1 space to the left, the msb into the carry bit and the carry bit into the lsb
29
Circular shift right
Pushes every value 1 space to the right, the lsb into the carry bit and the carry bit into the msb
30
Bitwise Masks
Apply another binary value with an AND, OR or XOR | Use boolean algebra on binary values by using each pair of corresponding values
31
OR masking
0: The output is the same as the input 1: The output is 1 (set the bit)
32
AND masking
0: The output is 0 (clear the bit) 1: The output is the same as the input
33
XOR masking
0: The output is the same as the input 1: The output is the opposite of the input (toggle the bit)
34
Fixed point binary
At a fixed point is a metaphorical decimal point, after that comes negative values of 2
35
First 5 coefficients after the fixed point
0.5, 0.25, 0.125, 0.0625, 0.03125
36
How does moving the decimal point affect it?
Having more bits before the decimal point increases the range but decreases the accuracy
37
What is a floating point binary number made up of
A mantissa and an exponent | mantissa x 2^exponent
38
Where is the decimal point at the start in floating point binary?
Between the first 2 bits
39
Positive floating point -> decimal
1. Find the value of the exponent 2. Move the decimal point by that many spaces to the right 3. Find the value of that as if it was a fixed point decimal
40
Negative floating point -> decimal
1. Find the two’s complement of the mantissa 2. Find the value of the exponent 3. Move the decimal point that many spaces to the right 4. Find the value as if it was a fixed point decimal 5. Put a sign in front of your value
41
How to know if a mantissa/exponent is negative
It will have a 1 as the msb (in two's complement)
42
Negative Exponents decimal conversions
1. Find the value of the exponent remembering the negative left value 2. Move the decimal point that many places to the left, as if there were all 0s to the left of your number 3. Find the value as if it was a regular fixed point number
43
Doing two's complement on a binary number with a point
Add the 1 to the lsb
44
Normalised positive number
Has a sign bit 0 and a 1 for the next bit
45
Normalising a positive number
1. Move the decimal point to the right until it is in front of the 1 2. Add as many zeroes to the end as you moved right by 3. Subtract the amount of spaces you moved to the right from the exponent 4. Write out the normalised number with the mantissa and exponent
46
Normalised negative number
Has a sign bit 1 and a 0 for the next bit. Leading 1s don't change the value.
47
Normalising a negative number
1. Move the decimal point to the right until it is in front of a 0 2. Add as many zeroes to the end as you moved right by 3. Subtract the amount of spaces you moved to the right from the exponent 4. Write out the normalised number with the mantissa and exponent
48
Positive denary -> floating point binary
1. Convert it to fixed point binary 2. Move the decimal point to the left until it is in front of the first 1 3. Pad the RHS with zeroes to keep the same length if necessary 4. Set the exponent equal to how many spaces you moved to the left
49
Negative denary-> floating point binary
1. Convert the positive number to fixed point (write a 0 at the start) 2. Take the two’s complement 3. Convert as you would a positive number
50
Floating point addition
1. Convert each floating point number to fixed point binary by shifting the binary point right by the value of the exponent 2. Sum the two values 3. Convert back to floating point and normalise
51
Floating point subtraction
1. Convert each floating point number to fixed point binary by shifting the binary point right by the value of the exponent 2. Take the two’s complement of the negative value 3. Sum the two values 4. Convert back to floating point and normalise