14-440-127 Recitation 8 Problems- Solutions

# 14-440-127 Recitation 8 Problems- Solutions - 14:440:127...

This preview shows pages 1–3. Sign up to view the full content.

14:440:127- Introduction to Computers for Engineers Problems for students to attempt in Recitation 8 1) Predict the result of the following computation (consider that ans will be a uint16): uint16(29493929)*uint16(2949329) Then, try it in Matlab. 65535. Why? A 16 bit unsigned integer has 16 digits, so add up the values of those places (2 0 + 2 1 + 2 2 + … + 2 15 ), or, even better, 2 16 -1 since the largest 16 digit number is 1 less than the smallest 17 digit number (a 1 followed by 16 zeroes) 2) Convert 10101101 (Base 2) to base 10. 1*2 7 +0*2 6 +1*2 5 +0*2 4 +1*2 3 +1*2 2 +0*2 1 +1*2 0 1*2 7 +1*2 5 +1*2 3 +1*2 2 +1*2 0 = 173 3) Convert 348 (Base 10) to base 2. _ _ _ _ _ _ _ _ _ _ 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 _ _ _ _ _ _ _ _ _ _ 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 _ _ _ _ _ _ _ _ 348 – 256 = 92 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 0 1 _ _ _ _ _ _ 92 – 64 = 28 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 0 1 0 1 _ _ _ _ 28 – 16 = 12 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 0 1 0 1 1 1 0 0 12-8-4 = 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 348 base 10 is 0101011100 base 2 4) Create a structure called student that contains 3 fields: exam1, exam2, and exam3. Now, create a 100 element vector of students, and assign each student random grades (between 0 and 100) for each of the exams. Assuming the exam grades are weighted equally, which student (number) has the highest course grade? Which student has the lowest course grade?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
% i wrote this using loops as much as possible % so that you can practice loops %randomly assign grades for s = 1:100 student(s).exam1 = ceil(101*rand(1))-1; % ceil(101*rand(1)) gives integers 1 to 101 % ceil(101*rand(1))-1 gives integers 0 to 100 % floor(101*rand(1)) also gives integers 0 to 100 student(s).exam2 = ceil(101*rand(1))-1; student(s).exam3 = ceil(101*rand(1))-1; end
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

14-440-127 Recitation 8 Problems- Solutions - 14:440:127...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online