In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the C language algorithms commonly used in single-chip microcomputer", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the C language algorithms commonly used in single-chip microcomputer"?
Algorithm (Algorithm): the basic ideas, methods and steps of computer problem solving.
Description of the algorithm: a description of the methods and steps taken to solve a problem or to complete a task, including what data is needed (what data to input and what results to output), what structure to use, what statements to use, and how to arrange these statements. Natural language, structured flowchart, pseudo code and so on are usually used to describe algorithms.
First, simple algorithms such as counting, summation and factorial
This kind of problem should use a loop, and we should pay attention to determine the initial value, final value or end condition of the loop variable according to the problem, and pay more attention to the initial value of the variable used to represent counting, sum, and factorial.
Example: use random function to generate 100 random integers in the range of [0meme 99]. The numbers on the statistics are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 0 respectively and print them out.
This problem is processed by using an array, using the array a [100] to store 100 random integers, and the array x [10] to store the numbers on each bit as 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, respectively. That is, the number of bits with 1 is stored in x [1], and the number of bits with 2 is stored in x [2]. The number of bits with 0 is stored in the array x [10].
Second, find the greatest common divisor and least common multiple of two integers
Analysis: the algorithm idea of finding the maximum common divisor: (least common multiple = product of two integers / maximum common divisor)
(1) for the known two numbers m > n, m > n.
(2) m divided by n to get the remainder r
(3) if r is 0, then n is the largest common divisor obtained, and the algorithm ends; otherwise, execute (4)
(4) m ← n ← r, then repeat (2).
For example: ask m = "14" >
M n r
14 6 2
6 2 0
Third, judge primes
A number that can only be divisible by 1 or itself is called the basic idea of prime: take m as a divisor and 2-INT as a divisor. If it is not divisible, m is a prime, otherwise it is not. (can be implemented with the following program segments)
5. Scheduling problem
1. Sorting by selection (ascending order)
Basic ideas:
1) for the sequence with n numbers (stored in the array a (n)), select the smallest number and exchange positions with the first number
2) except for the first number, select the smallest number among the other 1 numbers, and exchange positions with the second number.
3) by analogy, the sequence has been arranged in ascending order after selecting nmure once.
The program code is as follows:
3. Sort by merging (merge two ordered arrays An and B into another ordered array C, ascending)
Basic ideas:
1) compare the first element in the An and B array, and put the small element into the C array.
2) compare the next element of the array with the larger element of the other array after the last comparison, and repeat the above comparison process until a certain array is lined up first
3) copy the remaining elements of another array into the C array and complete the merge sorting.
The program segment is as follows:
Think about: rewrite the above program to find a function Find, if found, then return the subscript value, can not find the return-1
The basic idea of ②: put a column of numbers in the array a [1]-- a [n], and the key value to be found is key. Compare key with the elements in the an array from beginning to end. If the same, the search succeeds, if it cannot be found, the search fails. (the search subprocess is as follows. Index: stores the subscript of the found element.)
VIII. Limiting filtering method
Clipping filtering is an effective method for random interference.
The basic method: compare the two sampling values y (n) and y (n-1) of adjacent n and n-1 times, and determine the maximum allowable deviation of the two sampling according to experience. If the difference between the two sampling values exceeds the maximum deviation range, it is considered that random interference can occur, and that the latter sampling value y (n) is illegal and should be deleted. After deleting y (n), y (n-1) can be used instead of y (n); if it does not exceed the maximum deviation range allowed, the sampling value is considered to be valid.
The following is the limiting filtering program: (the A value can be adjusted according to the actual situation, value is a valid value, and new_value returns a valid actual value for the current sampling value filtering program)
ten。 Arithmetic average filtering method
The arithmetic average filtering method is suitable for filtering general signals with random interference. The characteristic of this kind of signal is that the signal itself fluctuates up and down near a certain value range, such as measuring flow rate and liquid level.
The basic method is to find such a Y according to the input N sampling data, so that the sum of squares between Y and each sampling value is minimized.
When writing the program of arithmetic average filtering method, we should pay close attention to:
one。 In order to speed up the speed of data measurement, the measured data can be stored in memory first, and then the average value of N data can be calculated after measuring N points.
two。 Choose the appropriate data format, that is, fixed-point numbers or floating-point numbers. The procedure is as follows:
12. First-order lag filtering method
Advantages: good suppression of periodic interference, suitable for situations with high fluctuation frequency
Disadvantages: phase lag, low sensitivity. The degree of lag depends on the value of a. The interference signal whose filtering frequency is higher than the sampling frequency can not be eliminated. The procedure is as follows:
The function of each correction link of PID regulator:
Proportional link: respond immediately and proportionally to the deviation signal e (t) of the control system. Once the deviation occurs, the regulator immediately produces the control effect to reduce the deviation.
Integral link: mainly used to eliminate static error and improve the error-free degree of the system. The larger the integral time constant TI is, the weaker the integral effect is, and vice versa.
Differential link: it can reflect the changing trend (change rate) of the deviation signal, and introduce an effective early correction signal into the system before the value of the deviation signal becomes too large, so as to speed up the action speed of the system and reduce the adjustment time.
PID regulator is a kind of linear regulator, which controls the control object by linearly combining the ratio (P), integral (I) and differential (D) of the deviation between the given value r (t) and the actual output value c (t).
14. Open root algorithm
Fast algorithm of opening Square of single Chip Microcomputer
Because of the need of work, it is necessary to realize the operation of opening the root number on the single-chip microcomputer. At present, most of the square methods are Newton iterative method. After looking up some data, I found a faster method than the Newton iterative method. I dare not enjoy it alone. I hope it will be of some help to introduce it to you.
1. Principle
Because of typesetting, we use pow to denote the Y power of X and B [0], B [1],..., B [Mmur1] to denote a sequence, where [x] is the subscript.
Suppose:
B [x], b [x] are binary sequences with values of 0 or 1.
M = B [m-1] * pow (2mam-1) + B [m-2] * pow (2mam-2) +... + B [1] * pow (2m-1) + B [0] * pow (2L0)
N = b [n-1] * pow (2m n-1) + b [n-2] * pow (2m m m 2) +... + b [1] * pow (2m 1) + n [0] * pow (2m 0)
Pow (NMagne2) = M
(1) the highest bit b [n-1] of N can be obtained directly from the highest bit B [m-1] of M.
Let m be known, because pow (2, mmur1)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.