
功能函数
rocketzzy
嵌入式软件应用
展开
-
c语言高效位运算函数之 __builtin_
转自博客园int __builtin_ffs (unsigned int x)返回x的最后一位1的是从后向前第几位,比如7368(1110011001000)返回4。int n = 1;//1int m = 8;//1000cout<<__builtin_ffs(n)<<endl;//输出1cout<<__builtin_ffs(m)<<endl;//输出4int __builtin_clz (unsigned int x)返回前导的0的个数。转载 2021-05-08 09:35:37 · 1045 阅读 · 0 评论 -
C语言判断mcu或者cpu的大端小端单片机用
见代码判断函数返回值就行原理是用char型指针指向int型数的低地址,强制转换后判断值typedef enum{ LITTLE_ENDIAN, BIG_ENDIAN, }DISTINGUISH_ENDIAN;unsigned char little_or_big_endian(void){ int test_int = 0x1234; return ( *((char *)&test_int ) == 0x34 ) ? LITTLE_ENDIAN : BIG_ENDIAN原创 2021-04-22 09:29:41 · 435 阅读 · 0 评论 -
C语言校验码计算数据总和后取余256
使用方法:dev c++编译后生成exe文件,方便以后使用每输入一个16进制格式数据后加空格,输入完毕加回车,大小写任意example: FF fa Fa 09 00(+enter)通信中的校验方法之一:每个数据相加之后取余放在数据末尾#include"stdio.h"#include "stdint.h"#include <string.h>typedef unsigned char uint8_t;typedef unsigned short uint16_t;typed原创 2021-04-16 10:58:51 · 1940 阅读 · 0 评论 -
C语言数组储存搜索RAM暂存断电失效的储存方法
参考应用场景:单片机中无需断电保存的特定数据的保存与搜索可自定义数据大小和数据格式,无重复数据则写入,有重复数据则返回储存位置分享些代码,等待有缘人指导DEV C++编译,main函数写了自动验证函数有效性,已通过中国加油!#include<stdio.h>#define MAX_ROWS_NUMBER 5#define MAX_COLUMNS_NUMBER 6 typedef unsigned char set_format; set_format store_a原创 2021-03-06 15:09:00 · 333 阅读 · 0 评论 -
C语言UNIX时间戳4字节转北京时间
伸手党留个评论就可以拷走使用!!!DEV C++编译可用,输出正确可优化处欢迎讨论!#include"stdio.h"#include "stdint.h"#include <string.h>#define TIME_ZONE 8 //北京时间 uint8_t Common_month_day[12]={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //平年 uint8_t Leap_month_d原创 2021-03-06 14:38:12 · 2266 阅读 · 10 评论