02.10.2019 Views

UploadFile_6417

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

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

Representation of Numbers 255<br />

Solution<br />

MATLAB script:<br />

>> x = -7:7<br />

x =<br />

-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7<br />

>> y = OnesComplement(x,4)<br />

y =<br />

8 9 10 11 12 13 14 0 1 2 3 4 5 6 7<br />

Note that the number 15 is missing since we do not have −0 inour original<br />

array.<br />

□<br />

Two’s-complement format The disadvantage of having two codes for<br />

the number 0 is eliminated in this format. Positive numbers are coded as<br />

usual. The B-bit two’s-complement, ˜x, ofapositive integer x is given by<br />

˜x =¯x + 1=2 B − x or x +˜x =2 B (6.31)<br />

where the second equality is obtained from (6.30). Once again, the<br />

MSB of the representation provides the sign bit. Thus, using (6.31) the<br />

two’s-complement format representation 3 is given by<br />

x (2) =<br />

{ x, x ≥ 0<br />

|˜x|, x

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

Saved successfully!

Ooh no, something went wrong!