Fall 2014 CSCI 255 Homework 13

This assignment is due in class on 24 November, or can be turned in by 2:00 on 24 November on the Homework 13 dropoff on Moodle, or can be personally delivered to a CSCI faculty member at the senior project presentation on 1 December with a late penalty of 0.1 points.

C expressions!

Here are twenty C expressions. Express the value of each as an integer. You really ought to use the C Reference Card to answer this questions.

Some of these are pretty tricky. Most of these expressions would also be legal in Java and, in that case, would yield the same value.

  1. 5 / 3
  2. 5 % 3
  3. 4 / 2 * 4
  4. (2, 3) + 5
  5. 6 > 5 > 4
  6. 21 && 14
  7. 21 & 14
  8. 21 || 14
  9. 21 | 14
  10. 21 ^ 14
  11. -21
  12. ~21
  13. !21
  14. 5 > 4 ? 3 : 2
  15. 21 << 2
  16. 21 >> 2
  17. 21 << 2 + 3
  18. 1 && 0 == 1
  19. 1 & 0 != 0
  20. 100 & 0x0F

Problem 2

Suppose the following two characters are being transmitted, over an RS-232 connection, in 19200/8-O-1 (that’s a letter ‘O’ between the 8 and 1). Show the sequence of voltage levels that would be used to transmit the characters.

  1. 'M'
  2. '3'

Problem 3

Suppose you have an 12-bit ADC converter, similar to the ADS1015, and that the range of the input analog voltage is from 0v to 3v. What is the 12-bit value that would be used to encode the following input analog voltages?

  1. 0.3v
  2. 2.55v

Problem 4

Suppose you are using PWM to light an LED with a period of 1 msec and a duty cycle of 40%. Write a little piece of psuedo-code that accomplishes this task.