吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 565|回复: 1
收起左侧

[会员申请] 申请会员 ID :eagle860

[复制链接]
吾爱游客  发表于 2024-2-17 16:20
1、申请 ID:eagle860
2、个人邮箱:eagle860@163.com
3、原创技术文章:精通嵌入式C程序

附几个工作中原创的C程序

1.高效CRC-CCITT算法,占用FLASH少,效率高
uint16_t cal_crc(uint16_t crc, uint8_t *buf, uint16_t n)
{
    const uint8_t *p = buf;
    while (n--)
        {
        uint16_t t = (crc ^ *p++) & 0xFF;
        t ^= ((t & 0x0F) << 4);
        crc = (crc >> 8) ^ (t << 8) ^ (t << 3) ^ (t >> 4);
    }
    return crc;
}

2.复活节算法
void vEasterCalculate(uint8_t ubScrYy,uint8_t *ubDstDay,uint8_t *ubDstMth)
{
    uint16_t N,A,B,Q,M,W;
    N = ubScrYy + 100;
    A = N % 19;
    Q = N / 4;
    B = (7 * A + 1) / 19;
    M = (11 * A + 4 - B) % 29;
    W = (N + Q + 31 - M) % 7;
    if(M + W > 25) {
        *ubDstDay = 56 - M - W;
        *ubDstMth = 3;
    }
    else if(25 == (M + W)) {
        *ubDstDay = 31;
        *ubDstMth = 3;
    }
    else {
        *ubDstDay = 25 - M - W;
        *ubDstMth = 4;
    }
}

3.通用二分查找算法
void *search_pre(const void *key, const void *base, uint16_t n, uint8_t size,
                 int8_t (*cmp)(const void *, const void *), const void **pre)
{
    uint16_t sml, big, mid;
    const void *p;
    int8_t cmp_result;

    sml = 0;
    big = n - 1;

    while (sml < big) {
        mid = (sml + big) >> 1;
        p = (const uint8_t *)base + (mid * size);
        cmp_result = cmp(key, p);

        if (cmp_result < 0) {
            big = mid;
        }
        else if (cmp_result > 0) {
            sml = mid + 1;
        }
        else {
            if (pre != NULL) {
                if (mid == 0) {
                    *pre = NULL;
                }
                else {
                    *pre = (const uint8_t *)p - size;
                }
            }
            return ((void *)p);
        }
    }
    if (pre != NULL) {
        if (sml <= 0) {
            *pre = NULL;
        }
        else {
            *pre = (uint8_t *)base + (sml-1) * size;
        }
    }
    return NULL;
}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Hmily 发表于 2024-2-19 10:33
抱歉,未能达到申请要求,申请不通过,可以关注论坛官方微信(吾爱破解论坛),等待开放注册通知。

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 04:52

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表