Binary number system Flashcards
Overflow error, all things binary (24 cards)
Unsigned binary
All unsigned means is the there is no indication of + or -, assumed to be a positive integers.
Range of unsigned binary
This is referring to the minimum and maximum values a certain number of bits can represent. Not the same as doing 2^n, as this shows the number of different values we could represent, not what the maximum value is. The minimum is always 0, maximum is 2^n -1.
Addition of unsigned binary
Put the two binary numbers on top of each other, like column addition, with space for carried digits. Then just compare each digit on top of each other. Basic rules: 0+0 = 0, 1+0=1, 0+1=1, 1+1 = 0 carry the one to under next comparison. 1+1+1 = 1, and carry 1.
Multiply unsigned binary
Line up two values as far right as possible. Then go through multiplying the top by each digit of the bottom. So 10110111 x 1 = 10110111, 10110111 x 0 = 00000000. Very simple. Every time you move a number in of your multiplication number, put a 0 at the start before anything, should cause an extra digit on the left each time. When you’ve multiplied each one, add them for a final answer.
Overflow errors
When adding or multiplying binary, sometimes the number produced can be too large for the specified number of bits. Therefore, the actual number can’t be represented so theres an error. For example if there are a specified 8 bits, but the answer needs 9 bits as theres a 1 in the left most bit, theres an overflow error as 8 bits can’t represent it. In calculations, remove overflowed digits, don’t show any digits above the specified bit number.
Signed binary integers
Unlike unsigned binary, signed binary can be negative as well. To represent negative binary two’s compliment is needed. Can be used on positive binary as well, but its necessary for negative numbers
Representing binary with two’s compliment
Left most bit is set as negative, e.g for an 8 bit number, it starts with -128, then 64, etc. For positive numbers, left most bit must be 0, rest is normal. For negative, left most must be 1. Then the others can be added to adjust what negative number it is.
-128 64 32 16 8 4 2 1
1. 0 1. 1 0. 0 0 1. = -79
Finding negative equivalent to positive numbers
It might ask you to show the equivalent to a + number as a negative, like 25 as -25, but in binary. Simply flip all digits except the lowest value thats a 1 not a 0
e.g 0010110 (22) becomes 1101010 (-22)
Addition in two’s compliment
Exactly the same as normal, just the first value is still a negative value when working out in denary, but literally no difference when adding. Overflow errors can be worse as they cause negative numbers to appear positive.
Subtracting numbers in two’s compliment
Subtraction can only be done with two’s compliment. Treat it as an addition, remember that its just 93 + (-35) for a subtraction. Convert both to two’s compliment, so you’ll have to make the second one negative, then add them.
Range of values in two’s compliment
Largest positive integer, is everything but the left most value, so it’s 1 less the the total bits, -1. For example in an 8 bit number, it would be 2^7 -1. For the smallest possible integer, it would be only the left most integer. So in an 8 bit number, it would be -2^7. Largest is 2^7 - 1, smallest is -2^7.
Fractions in binary
The scale just continues with 1/2, 1/4, 1/8 and so on. Basically keeps halving like normal. Same in two’s compliment
Fixed point form
Binary point set at a specific place, so the ratio of bits for the fractional part and the whole part cannot change. Therefore a trade off has to be made, lots of bits could be on the whole side, allowing a large number to be represented, but sacrificing the ability for accuracy in the fractional part, and vice versa.
Floating point
The binary point can be moved, allowing both very large numbers, and very small precise numbers to be represented. Expressed with a mantissa and exponent.
Mantissa and exponent
Mantissa is a longer binary number, and the exponent is a shorter one that is used to scale the size of the mantissa. It is the same as standard form. Both use two’s complement.
Floating point to denary
Convert exponent to denary, if its +, move the point that number of places to the right, if its negative, move it that number of places left. Note, if it goes off the end, for a positive mantissa, fill new values with 0’s, for negative mantissa, fill them with 1’s. Then work out mantissa into denary normally.
Normalisation of floating point
Positive mantissa is normalised if it starts with 0.1. Negative mantissa is normalised if it starts with 1.0. Do this, then count how many spaces you moved it. If you had to move it right, then subtract this number from exponent, and rewrite in binary. If you had to move it left, then add this number to the exponent, and rewrite in binary.
Denary to floating point
Convert to fixed point binary, then normalise, and adjust exponent.
Overflow
When the number is too large to be represented by the number of allocated bits.
Underflow
Number is too small to be properly represented, not enough decimal bits.
Truncation
If not enough bits for number, just removes bits it can’t represent, loses accuracy
Rounding
Same as truncation, but you just make sure the last represented number is a 1.
Absolute error
After rounding or truncation, this is the difference between what the number is supposed to be, verses what you’ve represented it as.
Relative error
Just the absolute error, divided by the original number. Can be x 100 to give percentage relative error