Fundamental-concepts Flashcards

1
Q

Define two’s complement.

A

The two’s complement of an N-bit number is equal to the result of subtracting the number from 2N

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

two’s complement number: algorithm..

A
  1. Write out the number in binary.
  2. 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.

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

Two’s-complement of -28 using 8-bit quantities.

(Why 8-bits?)

A
  1. Assume 8 bit quantities (for simplicity’s sake)
  2. Write out 28 in binary form: 00011100
  3. Invert the digits. 11100011
  4. Add 1:. 11100100
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is the two’s-complement equal to the one’s-complement + 1?

A

The sum of a number and its ones’ complement is all 1 bits.

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

Two’s complementation representation

A
  1. Positive numbers are simply represented as themselves,
  2. Negative numbers are represented by the two’s complement of their absolute value.
  3. How do you know if the number being represented is positive or negative?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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 + ______.

A

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).

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

Advantage of two’s-complement system for representing numbers?

A

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

  1. simpler to implement and
  2. capable of easily handling higher precision arithmetic.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the two’s complement of 127?

A

127

0111 1111 == 127 

twosComplement(0111 1111 ) == 127

Work out the steps.

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

What ambiguity can arise if you throw around terms like two’s complement?

A
  1. Can mean either a number format or a mathematical operator.
  2. **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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the weight of the of the most significant bit in two’s-complement notation/representation?

A

Most significant bit has weight equal to the negative of the corresponding power of two.

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

What is the value of a N-bit number in two’s complement?

A
  1. Sum up the bits in usual fashion (the place determines which power of two) except for ..
  2. The MSB which is raised to (N-1) power and multiplied by -1.
  3. Add (`) and (2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The MSB determines the ___ of a number in a two’s-complement.

A

The MSB determines the sign of a number in a two’s-complement.

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

What is sign-and-magnitude representation?

A
  1. 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.
  2. The remaining bits in the number indicate the magnitude.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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
  1. A byte has 8 bits.
  2. The magnitude bits can range from 0000000 (0) to 1111111 (== 127 in base 10).
  3. Implies: numbers from −127 (base 10) to +127 (base 10) once the sign bit (the eighth bit) is set.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Two’s complement of zero and why?

A
  1. The two’s complement of zero is zero:
  2. inverting gives all ones, and
  3. adding one changes the ones back to zeros
  4. since the overflow is ignored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Sum of a number and its ones’ complement

A

The sum of a number and its ones’ complement is an N-bit word with all 1 bits, which is 2N − 1.

17
Q

With only one exception, starting with any number in two’s-complement representation, if all the bits are flipped and 1 added, the two’s-complement representation of the negative of that number is obtained. Which number is that?

A
  1. The two’s complement of the minimum number in the range will not have the desired effect of negating the number.
  2. For example, the two’s complement of −128 in an 8-bit system results in the same binary number.
-128 1000 0000 invert bits 0111 1111 add one 1000 0000

The two’s complement of −128 results in the same 8-bit binary number.

18
Q

Explain the output of the following program.

A