Lab Assignment 03 Solutions PDF

Title Lab Assignment 03 Solutions
Course Engineering Software Fundamentals
Institution University of Windsor
Pages 5
File Size 150 KB
File Type PDF
Total Downloads 36
Total Views 157

Summary

Download Lab Assignment 03 Solutions PDF


Description

Faculty of Engineering University of Windsor GENG 2320 Engineering Software Fundamentals 20w0 Fall Semester Lab Assignment 3: Data Representation—Solutions

Part 1: Integer Data Objective: Working with computer data representation. Do these calculations by hand with paper and pen and show your results to your GA. 1)

Find the 2’s complement of the following: a) 0001 1001 b) 1110 1010

(Solution:

Step 1: Reverse digits Step 2: Add 1

1110 0110 1110 0111

Step 1: Reverse digits Step 2: Add 1

0001 0101 0001 0110

) 2) Using 4-bit 2’s complement arithmetic add -7 and + 4; express the answer in binary. (Solution:

+7 = 0111 -7 = 1001 (2’s complement) +4 = 0100 1001 + 0100 -----1101

) 3)

Convert the binary number in 2) into a decimal number.

(Solution: This a negative number because the most-significant digits (left-most) is 1

negative. To find the decimal number must first apply two’s complement algorithm to find positive value, then negate it. Step 1: Reverse digits Step 2: Add 1

0010 0011

0011 = 0x23 + 0x22 + 1x21 + 1x20 = 3 Therefore

1101 = -3

) Do the following in MATLAB, but enter the following MATLAB command before you start: format hex 4) Set z1 to 1 as a signed integer of 32 bits and z2 to -1 as a signed integer of 32 bits. What hex codes did you get? (Solution: 00000001 and ffffffff

)

Set display back to normal mode: format 5) Set y = 65535 and x = 5 as an unsigned 16-bit integers. Add x + y. What result did you get? Can you explain why you got that result? (Solution: 65535 The maximum 16-bit positive number is 65535. When you go beyond that number, MATLAB will set the result to the maximum value. )

Part 2: Character Data Objective: Working with character data. 6) The MATLAB function slCharacterEncoding is used to determine or change MATLAB’s character coding. Go to HelpDocumentation and enter the name of this function and read the help file. The character coding in MATLAB can be obtained using the command: slCharacterEncoding() 2

Enter this command. What default encoding does MATLAB use? Now enter the character a = ˈAˈ Check the Workspace Window and find out how many byes it is. (Solution: windows-1252, 2 bytes) 7) Now change the encoding to US-ASCII. Use slCharacterEncoding() to make sure you changed it properly. Now define the character B = ˈBˈ. How many bytes is it? Now use the MATLAB function dec2hex(B) to find the hex coding for B. What is the answer? How does it compare to the value in the ASCII table in the lecture notes? (Solution: 2 bytes, 42 HEX) 8) The MATLAB function hex2poly() will allow take a hex value as a string as an argument and return the binary equivalent. Use this to find the binary of following hex numbers a) 0x41 b) 0xFA c) 0xABC Note that it is common to indicate that hex number are specified by using the prefix “0x” where 0 is zero. (Solution: 1 1

0 1 1

0 1 0

0 1 1

0 1 0

0 0 1

1 1 0

0 1

1

1

1

0

0

) 9) In MATLAB, and in programming languages as well, characters are 1 byte (8 bits) long, and computers will treat character data as unsigned 8-bit decimal integers. The MATLAB function char(unint) takes an unsigned decimal integer as its argument and will return the associated 3

character. For integers between 0 and 127, the ASCII character will be returned, although this will be a blank character if the associated character is not printable. But if you are working with hex data, you must first convert the hex number to a decimal number, because, as mentioned, the computer treats character data as decimal integers. The MATLAB function hex2dec(hexString) takes a hexadecimal number represented as a string and returns the decimal equivalent. Enter the following and find the result: a) b) c) d) e) f) g)

char(65) char(97) char(17) char('a') dec2hex('a') hex2dec('61') char(hex2dec('61'))

Show your results to your designated GA. (Solution: >> char(65) ans = 'A' >> char(97) ans = 'a' >> char(17) ans = '' >> char('a') ans = 'a' >> dec2hex('a') ans = '61' >> hex2dec('61') ans = 4

97 >> char(hex2dec('61')) ans = 'a' )

Part 3: MATLAB Numeric Data 10)

Define the value -5 as the following variables: a) a as an unsiged 32-bit integer, b) b as a signed 32-bit integer, c) c as a single precision floating point number.

Now set MATLAB to hexadecimal format and display a, b and c. Show your result to your GA. (Solution:

a) 00000000 b) fffffffb c) c0a00000 )

5...


Similar Free PDFs