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 253<br />

rule to compute addition, another rule to compute subtraction, and a<br />

way tocompare two magnitudes to determine their relative value before<br />

subtraction.<br />

MATLAB Implementation MATLAB is a 64-bit floating-point computation<br />

engine that provides results in decimal numbers. Therefore,<br />

fixed-point binary operations must be simulated in MATLAB. It provides<br />

a function, dec2bin, toconvert a positive decimal integer into a B-bit<br />

representation, which is a symbol (or a code) and not a number. Hence<br />

it cannot be used in computation. Similarly, the function bin2dec converts<br />

a B-bit binary character code into a decimal integer. For example,<br />

dec2bin(3,3) gives 011 and bin2dec(’111’) results in 7. To obtain a<br />

sign-magnitude format, a sign bit must be prefixed. Similarly, to convert a<br />

sign-magnitude format, the leading bit must be used to impart a positive<br />

or negative value. These functions are explored in Problem P9.1.<br />

One’s-complement format In this format, the negation (or complementation)<br />

of an integer x is obtained by complementing every bit (i.e., a<br />

0isreplaced by 1 and a 1 by 0) in the binary representation of x. Suppose<br />

the B-bit binary representation of x is b B−1 b B−2 ··· b 0 ; then the B-bit<br />

one’s-complement, ¯x, ofx is given by<br />

¯x △ = ¯b B−1 ¯bB−2 ··· ¯b 0<br />

where each bit ¯b i is a complement of bit b i . Clearly then<br />

x +¯x ≡ 11 ... 1=2 B − 1 (6.29)<br />

The MSB of the representation once again represents the sign bit,<br />

because the positive integer has the MSB of 0 so that its negation (or a<br />

negative integer) has the MSB of 1. The remaining bits represent either<br />

the number x (if positive) or its one’s-complement (if negative). Thus,<br />

using (6.29) the one’s-complement format representation 2 is given by<br />

x (1)<br />

∆<br />

=<br />

{<br />

x, x ≥ 0<br />

|x|, x

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

Saved successfully!

Ooh no, something went wrong!