o****e 发帖数: 536 | 1 Problem statement:
We often use a phase locked loop capable of generating a new frequency which
is locked in
phase to a clock that is supplied at a different frequency. The relationship
between the two
frequencies is given by a rational fraction - that is, there is a
multiplication step and a
division step, both of which are integers, to convert from one frequency to
the other.
For example, we may have a 10 MHz clock, and we need a 12 MHz clock which is
phase
locked to the 10 MHz clock. In this case we would use a multiplier of 6 and
a divisor of 5 to
get 10,000,000 * 6 = 60,000,000; 60,000,000 / 5 = 12,000,000.
As a generic exercise, write a routine which when given two integers will
return an integer
representing the smallest multiplier required to convert from one frequency
to the other.
(The divisor is implied based on the returned multiplier.)
Routine Signature:
int multiplier(int BaseFreq, int OutputFreq)
Constraints:
sizeof(int) = 32
BaseFreq and OutputFreq will be between 1 and 2147483647 inclusive
Examples:
1) multiplier(10000000,12000000) returns 6. This is the example above.
2) multiplier(12000000,10000000) returns 5. Same as example 1, but the
result is
multiply by 5, divide by 6.
3) multiplier(123456,54321) returns 18107. 123456 * 18107 = 2235417792;
2235417792 / 41152 = 54321. |
|