4.1 (DATA TYP) Flashcards

1
Q

What are 2 ways we can represent negative numbers in binary?

A

Sign and magnitude
Twos compliment

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

How does sign and magnitude work?

A

The first bit is used as a sign
if it is a 0 the number is positive, if it is 1 it is negative
Halves the maximum value

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

How does twos complement work?

A

Invert the binary bits
Add one
e.g.
12 => 01100
01100 => 10011
+1
10100
The most significant bit now represents the negative starting point (-16) then the rest represent how many more it is than that (+4) giving the number (-16+4=-12)

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

How to normalise a floating point number

A

remove leading 1s (negatives) or 0s(positives)
000011001.01
01100101 5steps therefore 0101

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

Name the 5 primitive data types

A

Integer
real
bool
char
string

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

In signed data what does the Most Significant Bit (MSB) being a 1 represent

A

It is negative

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

In signed data what does the Most Significant Bit (MSB) being a 0 represent

A

It is positive

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

Range possible of a number using sign and magnitude (8B)

A

-127 to 127

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

How to do twos compliment

A
  • invert the bits
  • add 1
    MSB now represents negative offset, the rest count up from it
    e.g.
    -12:
    01100 -absolute value
    10011 -flip
    10100 -add 1

now, -16 + 4= -12

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

representation of negative floats in twos complement

A

Negative numbers can also be represented in floating point form using two’s Complement

The MSB is used to represent the negative offset of the number, and the bits that follow it are used to count upwards
The fractional values are then added to the whole number

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

Steps for adding or subtracting floating point numbers

A

Ensure the numbers have the same exponent before performing arithmetic
Perform the binary addition or subtraction on the mantissa
Ensure the result is in a normalised form
Determine Sign

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

Explain the XOR operator

A

If only 1 of the bits is 1 in the binary number or the mask, the result will be 1. Otherwise, the result will be 0.

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