02.10.2019 Views

UploadFile_6417

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

254 Chapter 6 IMPLEMENTATION OF DISCRETE-TIME FILTERS<br />

For example, using 3 bits, we can represent numbers from −3 to3as<br />

-3 -2 -1 -0 0 1 2 3<br />

-+----+----+----+----+----+----+----+-<br />

100 101 110 111 000 001 010 011<br />

which is a different bit arrangement for negative numbers compared to<br />

the sign-magnitude format.<br />

The advantage of this format is that subtraction can be achieved by<br />

adding the complement, which is very easy to obtain by simply complementing<br />

a number’s bits. However, there are many drawbacks. There are<br />

still two different codes for 0. The addition is a bit tricky to implement,<br />

and overflow management requires addition of the overflow bit to the least<br />

significant bit (or 2 0 ).<br />

MATLAB Implementation The 1s-complement of a positive integer<br />

x using B bits can be obtained by using the built-in function<br />

bitcmp(x,B), which complements the number’s bits. The result is a decimal<br />

number between 0 and 2 B − 1. As before, the dec2bin can be used<br />

to obtain the binary code. Using (6.30), we can develop the MATLAB<br />

function, OnesComplement, which obtains the one’s-complement format<br />

representation. It uses the sign of a number to determine when to use<br />

one’s-complement and can use scalar as well as vector values. The result<br />

is a decimal equivalent of the representation.<br />

function y = OnesComplement(x,B)<br />

% y = OnesComplement(x,B)<br />

% ---------------<br />

% Decimal equivalent of<br />

% Sign-Magnitude format integer to b-bit Ones’-Complement format conversion<br />

%<br />

% x: integer between -2^(b-1) < x < 2^(b-1) (sign-magnitude)<br />

% y: integer between 0

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

Saved successfully!

Ooh no, something went wrong!