Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

The 2's complement representation, Exams of Number Theory

What decimal value does the two's complement 110011 represent? It must be a negative number, since the most significant bit (msb) is a 1. Therefore, find the ...

Typology: Exams

2022/2023

Uploaded on 03/01/2023

aarti
aarti 🇺🇸

4.5

(8)

224 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The 2’s complement representation
The 2’s representation is a variation on 1's complement which does not
have 2 representations for 0.
This makes the hardware that does arithmetic (addition, really) faster than
for the other representations.
A 3-bit example:
bit pattern: 100 101 110 111 000 001 010 011
1's comp: -3 -2 -1 0 0 1 2 3
2's comp: -4 -3 -2 -1 0 1 2 3
The negative values are all "slid" down by one, eliminating the extra
zero representation.
To add, subtract, or multiply two complement numbers, just perform the
operation as if the numbers are unsigned, and throw away any additional
bits generated. To perform negation, form the ones complement (subtract
from all ones (the representation of -1), then add 1.
pf3

Partial preview of the text

Download The 2's complement representation and more Exams Number Theory in PDF only on Docsity!

The 2’s complement representation

The 2’s representation is a variation on 1's complement which does not have 2 representations for 0. This makes the hardware that does arithmetic (addition, really) faster than for the other representations.

A 3-bit example: bit pattern: 100 101 110 111 000 001 010 011

1's comp: -3 -2 -1 0 0 1 2 3

2's comp: -4 -3 -2 -1 0 1 2 3

The negative values are all "slid" down by one, eliminating the extra zero representation.

To add, subtract, or multiply two complement numbers, just perform the operation as if the numbers are unsigned, and throw away any additional bits generated. To perform negation, form the ones complement (subtract from all ones (the representation of -1), then add 1.

How to get an integer in 2's comp. representation:

The positive values are the same as for sign mag. and 1's comp. They will have a 0 in the MSB (but it is NOT a sign bit!)

Positive: just write down the value as before Negative: use the positive value 00101 (+5) take the 1's comp. 11010 (-5 in 1's comp) add 1 + 1


11011 (-5 in 2's comp)

For example -30 is represented as 11111111 - 00011110 + 1 = 11100001

  • 1 = 11100010

To get the additive inverse of a 2's comp integer,

  1. Take the 1's comp.
  2. Add 1

Exercise What is the bit pattern for decimal 42 and -42 as 8 bit two’s complement numbers?

To add 1 without really knowing how to add: Start at LSB, for each bit (working right to left)

  1. While the bit is a 1, change it to a 0.
  2. When a 0 is encountered, change it to a 1 and stop.
  3. All other remaining bits are the same as before.

Example: What decimal value does the two's complement 110011 represent?

It must be a negative number, since the most significant bit (msb) is a 1. Therefore, find the additive inverse:

110011 (2's comp. -?) 001100 (1's complement)

  • 1

001101 (2's comp. +13)