networking · beginner · ~15 min
Convert a byte count to a sample count.
Software-defined-radio (SDR) captures store interleaved I/Q samples. Given a buffer size and the bytes per sample, compute how many complete samples it holds.
Implement int iq_sample_count(int nbytes, int bytes_per_sample) that returns how many whole samples fit in nbytes (integer division). Return 0 if bytes_per_sample <= 0.
nbytes: the buffer size in bytes.bytes_per_sample: bytes occupied by one I/Q sample.Returns nbytes / bytes_per_sample (truncated), or 0 when bytes_per_sample <= 0.
iq_sample_count(1024, 4) -> 256
iq_sample_count(10, 4) -> 2
iq_sample_count(10, 0) -> 0
bytes_per_sample <= 0: return 0 (avoid dividing by zero).Two integers: buffer size in bytes (nbytes) and bytes per sample.
The number of whole samples (nbytes / bytes_per_sample), or 0 if bytes_per_sample <= 0.
Integer division; guard bytes_per_sample <= 0 by returning 0.
int iq_sample_count(int nbytes, int bytes_per_sample) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.