4.1 (DATA TYP) Flashcards
What are 2 ways we can represent negative numbers in binary?
Sign and magnitude
Twos compliment
How does sign and magnitude work?
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 does twos complement work?
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 to normalise a floating point number
remove leading 1s (negatives) or 0s(positives)
000011001.01
01100101 5steps therefore 0101
Name the 5 primitive data types
Integer
real
bool
char
string
In signed data what does the Most Significant Bit (MSB) being a 1 represent
It is negative
In signed data what does the Most Significant Bit (MSB) being a 0 represent
It is positive
Range possible of a number using sign and magnitude (8B)
-127 to 127
How to do twos compliment
- 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
representation of negative floats in twos complement
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
Steps for adding or subtracting floating point numbers
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
Explain the XOR operator
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.