A brief discussion on an algorithm in C language

Publisher:cxx7848653Latest update time:2012-08-29 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I spent two days on Saturday and Sunday to come up with an algorithm to convert complex algorithms into simple ones. In fact, these were all algorithms I learned in school, but had not applied in practice.

Let's talk about this algorithm in detail.

For example, there is a one-dimensional array with 96 elements. I want to divide it into 32 columns and 3 rows, and then into 16 columns and 6 rows. I also want to take the table elements from the head of the row and column respectively. For example, tab[]={0x08,0xa0,.......,0xff}; (You may think of dividing it into a multidimensional array and then using two for loops, such as for(int i=0;i<3;i++)

{

for(int j=0;j<32;j++)

tab[i][j];

}

But it’s still not flexible enough)

How can I change it flexibly? It is impossible to list two data tables, right? I thought hard for two days and looked up old books. Finally, I used a shift method. First, I took the element count from its array table, and then did the shift and addition and subtraction operations.

I did a test and the result was quite good. See the picture

Click to browse the next page

In this way, you can get the size of the table and change the values ​​of a, b, 4, 5. To get the desired result. This can be made into a small subroutine. The compiled file is also quite small, suitable for selecting larger element tables. Sometimes short statements are not an advantage (in microcontrollers). Statements that are suitable for machine reading are good. Of course, which is better, 2+2 or 2*2? The machine knows, I believe, you know... If you can save the loop statement occupying MCU system resources. Haha, why not?

Reference address:A brief discussion on an algorithm in C language

Previous article:How to write a microcontroller program
Next article:Detailed explanation of the connection between MCU and 8255 chip

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号