C12 Embedded systems in MicroPython and C · Practice
Fixed-point arithmetic
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
What integer represents 1.25 in a Q format with 8 fraction bits?
Check
In Q format with 16 fraction bits, 0.75 and 2 are stored as integers. What's their product, shifted back right by 16, as an integer?
Check
The ADC reads 1484. What does (c * 3300 + 2047) / 4095 give, in integer arithmetic?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
Interpolate in integers: the table says 1357 → 100 and 2676 → 400. What does 2000 give, truncated?
Check
A computation multiplies a 12-bit code (up to 4095) by 100000 before dividing. What's the largest intermediate value? (A signed 32-bit int holds up to about 2.1 × 10⁹.)
Check
Read the potentiometer on ADC0. Print the raw code, then the voltage in millivolts rounded to the nearest whole millivolt, using only integer arithmetic.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
Write int tenths(int code) using the table from the play (codes at 0, 10, ... 80 °C), interpolating in integers. Print tenths(1500), then tenths(X) for X = 2450.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
−0.75 and 2.25 are multiplied in Q16.16.
(a)
What integer stores −0.75?
(b)
What integer does the product, shifted right by 16, give?
Check
A Q-format number has 8 fraction bits, in 16 bits.
(a)
What unsigned 16-bit pattern stores −0.5?
(b)
What is the largest magnitude it can hold, about?
Check
0.1 with 8 fraction bits, as an integer?
Check
Rounded millivolts for code 1000?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
Largest intermediate of a 12-bit code times 50000?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12