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.

Problems 297<br />

P6.24 MATLAB provides the built-in functions dec2bin and bin2dec to convert non-negative<br />

decimal integers into binary codes and vice versa, respectively.<br />

1. Develop a function B = sm2bin(D) to convert a sign-magnitude format decimal integer D<br />

into its binary representation B. Verify your function on the following numbers:<br />

(a) D = 1001 (b) D = −63 (c) D = −449 (d) D = 978 (e) D = −205<br />

2. Develop a function D = bin2sm(B) to convert a binary representation B into its signmagnitude<br />

format decimal integer D. Verify your function on the following<br />

representations:<br />

(a) B = 1010 (b) B = 011011011 (c) B = 11001<br />

(d) B = 1010101 (e) B = 011011<br />

P6.25 Using the function TwosComplement as a model, develop a function y = TensComplement<br />

(x,N) that converts a sign-magnitude format integer x into the N-digit ten’s-complement<br />

integer y.<br />

1. Verify your function using the following integers:<br />

(a) x = 1234, N=6 (b) x = −603, N=4 (c) x = −843, N=5<br />

(d) x = −1978, N=6<br />

(e) x =50,N=3<br />

2. Using the ten’s-complement format, perform the following arithmetic operations. In each<br />

case, choose an appropriate value on N for the meaningful result.<br />

(a) 123 + 456 − 789 (b) 648 + 836 − 452 (c) 2001 + 3756<br />

(d) −968 + 4539 (e) 888 − 666 + 777<br />

Verify your results using decimal operations.<br />

P6.26 The function OnesComplement developed in this chapter converts signed integers into one’scomplement<br />

format decimal representations. In this problem we will develop functions that<br />

will operate on fractional numbers.<br />

1. Develop a MATLAB function y = sm2oc(x, B) that converts the sign-magnitude format<br />

fraction x into the B-bit 1s-complement format decimal equivalent number y. Verify<br />

your function on the following numbers. In each case the numbers to be considered are<br />

both positive and negative. Also, in each case select the appropriate number of bits B.<br />

(a) x = ±0.5625 (b) x = ±0.40625 (c) x = ±0.953125<br />

(d) x = ±0.1328125 (e) x = ±0.7314453125<br />

2. Develop a MATLAB function x = oc2sm(y, B) that converts the B-bit one’s-complement<br />

format decimal equivalent number y into the sign-magnitude format fraction x. Verify<br />

your function on the following fractional binary representations:<br />

(a) y = 110110 (b) y = 0.011001 (c) y = 100110011<br />

(d) y = 111101110<br />

(e) y = 000010001<br />

P6.27 The function TwosComplement developed in this chapter converts signed integers into two’scomplement<br />

format decimal representations. In this problem we will develop functions that<br />

will operate on fractional numbers.<br />

1. Develop a MATLAB function y = sm2tc(x, B) that converts the sign-magnitude format<br />

fraction x into the B-bit two’s-complement format decimal equivalent number y. Verify<br />

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).<br />

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

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

Saved successfully!

Ooh no, something went wrong!