字符串的各种操作
来源:互联网 发布:stc单片机是中国的吗 编辑:程序博客网 时间:2024/06/04 17:44
淘宝店铺 : https://shop114292239.taobao.com
SCDN : http://blog.csdn.net/beyondmike
QQ : 276678408
Email : hxtiou@163.com
Mike :欢迎咨询单片机方案开发和技术培训
/****************************************************************************** Function : 字符串各种操作函数* Author : Mike--->欢迎咨询单片机培训* 淘宝店铺 : https://shop114292239.taobao.com* SCDN : http://blog.csdn.net/beyondmike * QQ : 276678408* Email : hxtiou@163.com * Copyright : 版权归 Mike 所有,请保留本人著作权,勿随意修改、随意发布,未经 允许不得用于其他商业用途*****************************************************************************/#define u8 unsigned char u8 char_to_hex(u8 c) //字符转HEX{ if(c >= 'A' && c <= 'F') { c = c - 'A' + 10; } else if(c >= 'a' && c <= 'f') { c = c - 'a' + 10; } else if(c >= '0' && c <= '9') { c -= '0'; } else { c = 0xff; } return c;}//0~15转成字符,必须跟spi_bt_rfinfo_read在同个bankchar hex_to_char(u8 num)//字符转HEX{ if (num >= 10) { return ('A' + num - 10); } else { return ('0' + num); }}int my_strlen(const char *cpSrc){const char *cpTemp = cpSrc;while(*cpTemp++);return cpTemp-cpSrc-1;} /******************************************************************************** Function Name : my_memset* Description : write value to mem* Input : *dst: destination pointer* val : value* cnt :length* Output : None* Return : None*******************************************************************************//**/void my_memset(void *dst, BYTE val, int cnt){BYTE *pDstTemp = (BYTE *)dst;while (cnt--){*pDstTemp++ = val;}}/******************************************************************************** Function Name : zeromem* Description : clear mem to 0* Input : *dst: destination pointer* cnt :length* Output : None* Return : None*******************************************************************************/void zeromem(void *dst, int cnt){my_memset(dst, 0, cnt);}/******************************************************************************** Function Name : my_memcpy* Description : copy data from src to dst* Input : *dst: destination pointer* *src: source pointer* cnt :length* Output : None* Return : None*******************************************************************************/void my_memcpy(void *dst, void *src, int cnt){BYTE *pDstTemp = (BYTE *)dst;BYTE *pSrcTemp = (BYTE *)src;while (cnt--){*pDstTemp++ = *pSrcTemp++;}}void u16memset(void *dst, BYTE val, int cnt){u16 *pdst = (u16*)dst;int cnt_temp = cnt/2;u16 u16val = (val<<8)|(val);while(cnt_temp--){*pdst++ = u16val;}if(cnt > ((cnt>>1)<<1)){u16val = *pdst;u16val &= 0xff00;u16val |= val;*pdst = u16val;}}void u16memcpy(void *dst, void *src, int cnt){u16 *pDstTemp = (u16 *)dst;u16 *pSrcTemp = (u16 *)src;int cnt_temp = cnt/2;while(cnt_temp--){*pDstTemp++ = *pSrcTemp++;}if(cnt > ((cnt>>1)<<1)){*pDstTemp &= 0xff00;*pDstTemp |= (*pSrcTemp & 0x00ff);}}/******************************************************************************** Function Name : dma_memcpy* Description : copy data from src to dst* Input : *dst: destination pointer* *src: source pointer* cnt :length* Output : None* Return : None*******************************************************************************//* Compare memory to memory */int my_mem_cmp(const void* dst, const void* src, u8 cnt){ const char *d = (const char *)dst, *s = (const char *)src; int r = 0; while(cnt-- && (r = *d++ - *s++) == 0) ; return r;}/******************************************************************************** Function Name : bmemcmp* Description : compare src and dst data same or different* Input : *dst: destination pointer* *src: source pointer* cnt :length* Output : None* Return : 0:different; 1:same*******************************************************************************/BOOL bmemcmp(void *dst, void *src, u32 byte_len){ int i = 0; u8 *dst_u8 = (u8*)dst; u8 *src_u8 = (u8*)src; for(i=0;i < byte_len;) { if(dst_u8[i] != src_u8[i]) { return 0; } i++; } return 1;}/******************************************************************************** Function Name : datacmp* Description : u32 data compare* Input : dst: destination data* src: source data* Output : None* Return : 0:same; 1:dst>src ; -1:dst<src*******************************************************************************/s8 datacmp(u32 dst, u32 src){s8 res = 0;if(dst > src)res = 1;else if(dst == src)res = 0;else if(dst < src)res = -1;return res;}/** * strcpy - Copy a %NUL terminated string * @dest: Where to copy the string to * @src: Where to copy the string from */char * _strcpy(char * dest, const char *src) {char *tmp = dest;while ((*dest++ = *src++) != '\0');return tmp;}/** * strncmp - Compare two length-limited strings * @cs: One string * @ct: Another string * @count: The maximum number of bytes to compare */int _strncmp(const char * cs, const char * ct, unsigned int count) {register signed char __res = 0;while (count) {if ((__res = *cs - *ct++) != 0 || !*cs++)break;count--;}return __res;}/******************************************************************************** Function Name : XCHDWORD* Description : exchange u32 data high_low byte* Input : Before the exchange of data* Output : None* Return : After an exchange of data*******************************************************************************/u32 XCHDWORD(u32 dwXCHData){u32 dwXCHDataTmp;((BYTE *)(&dwXCHDataTmp))[0] = ((BYTE *)(&dwXCHData))[3];((BYTE *)(&dwXCHDataTmp))[1] = ((BYTE *)(&dwXCHData))[2];((BYTE *)(&dwXCHDataTmp))[2] = ((BYTE *)(&dwXCHData))[1];((BYTE *)(&dwXCHDataTmp))[3] = ((BYTE *)(&dwXCHData))[0];return dwXCHDataTmp;}/******************************************************************************** Function Name : XCHWORD* Description : exchange u32 data high_low byte* Input : Before the exchange of data* Output : None* Return : After an exchange of data*******************************************************************************/u32 XCHWORD(u32 wXCHData){u32 wXCHDataTmp;((BYTE *)(&wXCHDataTmp))[0] = ((BYTE *)(&wXCHData))[1];((BYTE *)(&wXCHDataTmp))[1] = ((BYTE *)(&wXCHData))[0];return wXCHDataTmp;}
阅读全文
0 0
- 字符串的各种操作
- 字符串的各种操作
- 字符串的各种操作
- 字符串的各种操作
- C#字符串的各种操作
- Java字符串的各种操作。
- 各种操作字符串的方法
- 有关String 字符串的各种操作大全
- 各种字符串操作函数的实现
- python中字符串的各种操作
- NSRange,判断字符串的各种操作~
- 对字符串操作的各种笔试题
- c#对字符串的各种操作
- Qt中对字符串的各种操作
- c#对字符串的各种操作
- 3.2字符串-各种字符串操作函数的实现
- C语言常用的各种操作字符串的函数
- 各种字符串操作---可运行
- POST提交参数数据过大,设置tomcat的配置文件
- PLSQL
- 第四周
- MyBatis中遇到的一些问题
- javax.el.PropertyNotFoundExpection:Property 'xxx' not found on type java.lang.String
- 字符串的各种操作
- 字符串流 转换为cin形式进行读写
- 控制反转
- 初学Jsp
- Mybatis映射文件中的#{}与${}
- 928(1)
- python核心编程v2.0 第14章习题答案
- CodeForces 427D Match & Catch
- 使用translate对元素造成类似position:relative的影响