Fundamental-concepts Flashcards
Define two’s complement.
The two’s complement of an N-bit number is equal to the result of subtracting the number from 2N
two’s complement number: algorithm..
- Write out the number in binary.
- Invert the digits, and add one to the result.
Suppose we’re working with 8 bit quantities (for simplicity’s sake) and suppose we want to find how -28 would be expressed in two’s complement notation. First we write out 28 in binary form.
00011100
Then we invert the digits. 0 becomes 1, 1 becomes 0.
11100011
Then we add 1.
11100100
That is how one would write -28 in 8 bit binary.
Two’s-complement of -28 using 8-bit quantities.
(Why 8-bits?)
- Assume 8 bit quantities (for simplicity’s sake)
- Write out 28 in binary form: 00011100
- Invert the digits. 11100011
- Add 1:. 11100100
Why is the two’s-complement equal to the one’s-complement + 1?
The sum of a number and its ones’ complement is all 1 bits.
Two’s complementation representation
- Positive numbers are simply represented as themselves,
- Negative numbers are represented by the two’s complement of their absolute value.
- How do you know if the number being represented is positive or negative?
An N-bit two’s-complement numeral system can represent every integer in the range −_______ to + _____while ones’ complement can only represent integers in the range− ______ to + ______.
An N-bit two’s-complement numeral system can represent every integer in the range −(2N-1) to +(2N − 1 − 1)
while ones’ complement can only represent integers in the range−(2N − 1 − 1) to +(2N − 1 − 1).
Advantage of two’s-complement system for representing numbers?
Fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers (as long as the inputs are represented in the same number of bits and any overflow beyond those bits is discarded from the result). This property makes the system both
- simpler to implement and
- capable of easily handling higher precision arithmetic.
What is the two’s complement of 127?
127
0111 1111 == 127
twosComplement(0111 1111 ) == 127
Work out the steps.
What ambiguity can arise if you throw around terms like two’s complement?
- Can mean either a number format or a mathematical operator.
- **Example: **0111 represents decimal 7 in two’s-complement notation, but the two’s complement of 7 in a 4-bit register is actually the “1001” bit string
What is the weight of the of the most significant bit in two’s-complement notation/representation?
Most significant bit has weight equal to the negative of the corresponding power of two.
What is the value of a N-bit number in two’s complement?
- Sum up the bits in usual fashion (the place determines which power of two) except for ..
- The MSB which is raised to (N-1) power and multiplied by -1.
- Add (`) and (2)
The MSB determines the ___ of a number in a two’s-complement.
The MSB determines the sign of a number in a two’s-complement.
What is sign-and-magnitude representation?
- allocate one sign bit to represent the sign: set that bit (often the most significant bit) to 0 for a positive number, and set to 1 for a negative number.
- The remaining bits in the number indicate the magnitude.
You are a hardware designer and choose to use the sign-and-magnitude system. What is the range of values that a byte could represent?
- A byte has 8 bits.
- The magnitude bits can range from 0000000 (0) to 1111111 (== 127 in base 10).
- Implies: numbers from −127 (base 10) to +127 (base 10) once the sign bit (the eighth bit) is set.
Two’s complement of zero and why?
- The two’s complement of zero is zero:
- inverting gives all ones, and
- adding one changes the ones back to zeros
- since the overflow is ignored