15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Problems of Sign-Bit Systems<br />

<strong>General</strong>ly: An n-bit signed binary number system<br />

allows to represent the integers from −2 n−1 + 1 to<br />

+2 n−1 − 1.<br />

2 n−1 −1 positive numbers, 2 n−1 −1 negative numbers,<br />

and the zero<br />

Thus we represent<br />

#({〈〈s〉〉 − | s ∈ B n }) = 2 · (2 n−1 − 1) + 1 = 2 n − 1<br />

numbers all in all<br />

One number must be represented twice<br />

(But there are 2 n strings of length n.)<br />

10 . . . 0 and 00 . . . 0 both represent the zero as<br />

−1 · 0 = 1 · 0.<br />

signed binary Z<br />

0 1 1 1 7<br />

0 1 1 0 6<br />

0 1 0 1 5<br />

0 1 0 0 4<br />

0 0 1 1 3<br />

0 0 1 0 2<br />

0 0 0 1 1<br />

0 0 0 0 0<br />

1 0 0 0 -0<br />

1 0 0 1 -1<br />

1 0 1 0 -2<br />

1 0 1 1 -3<br />

1 1 0 0 -4<br />

1 1 0 1 -5<br />

1 1 1 0 -6<br />

1 1 1 1 -7<br />

We could build arithmetic circuits using this, but there is a more elegant way!<br />

c○: Michael Kohlhase 252<br />

All of these problems could be dealt with in principle, but together they form a nuisance, that at<br />

least prompts us to look for something more elegant. The two’s complement representation also<br />

uses a sign bit, but arranges the lower part of the table in the last slide in the opposite order,<br />

freeing the negative representation of the zero. The technical trick here is to use the sign bit (we<br />

still have to take into account the width n of the representation) not as a mirror, but to translate<br />

the positive representation by subtracting 2 n .<br />

The Two’s Complement Number System<br />

Definition 428 Given the binary string<br />

a = 〈an, . . . , a0〉 ∈ Bn+1 , where n > 1. The<br />

integer represented by a in the (n + 1)-bit two’s<br />

complement, written as 〈〈a〉〉 2s<br />

n , is defined as<br />

〈〈a〉〉 2s<br />

n = −an · 2 n + 〈〈an−1, . . . , a0〉〉<br />

= −an · 2 n n−1 <br />

+ ai · 2 i<br />

i=0<br />

Notation 429 Write B 2s<br />

n (z) for the binary string<br />

that represents z in the two’s complement number<br />

system, i.e., 〈〈B 2s<br />

n (z)〉〉 2s<br />

n = z.<br />

c○: Michael Kohlhase 253<br />

2’s compl. Z<br />

0 1 1 1 7<br />

0 1 1 0 6<br />

0 1 0 1 5<br />

0 1 0 0 4<br />

0 0 1 1 3<br />

0 0 1 0 2<br />

0 0 0 1 1<br />

0 0 0 0 0<br />

1 1 1 1 -1<br />

1 1 1 0 -2<br />

1 1 0 1 -3<br />

1 1 0 0 -4<br />

1 0 1 1 -5<br />

1 0 1 0 -6<br />

1 0 0 1 -7<br />

1 0 0 0 -8<br />

We will see that this representation has much better properties than the naive sign-bit representation<br />

we experimented with above. The first set of properties are quite trivial, they just formalize<br />

140

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!