C常用基础函数集合

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fuhanga123/article/details/78622370
/***  字符处理  ***/
#define MAKEWORD(a, b)      ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
#define LOWORD(l)           ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l)           ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
#define LOBYTE(w)           ((BYTE)(((DWORD_PTR)(w)) & 0xff))
#define HIBYTE(w)           ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))


字符提取,复制函数

// Copy一个WORD	// 指针变量按照大端字节:高位字节在低位字节的前面,也就是高位在内存地址低的一端
void CopyWord(void * pDest, const u16 value)
{
	*((BYTE *)pDest) = HIBYTE(value);
	*(((BYTE *)pDest) + 1) = LOBYTE(value);
}
// Copy一个DWORD	// 指针变量按照大端字节:高位字节在低位字节的前面,也就是高位在内存地址低的一端
void CopyDword(void * pDest, const u32 value)
{
	*((BYTE *)pDest) = HIBYTE(HIWORD(value));
	*(((BYTE *)pDest) + 1) = LOBYTE(HIWORD(value));
	*(((BYTE *)pDest) + 2) = HIBYTE(LOWORD(value));
	*(((BYTE *)pDest) + 3) = LOBYTE(LOWORD(value));
}

数制转换

// 十进制数转换为BCD数0X09->0X09		0X0B->0X11
BYTE ByteToBcd(BYTE num)
{
	return (num / 10) * 16 + (num % 10);
}

// BCD数转换为十进制数字节		0X12->0X0C
BYTE BcdToByte(BYTE uBcd)
{
	return (uBcd / 16) * 10 + (uBcd % 16);
}

eg:

	// 输入信号
	ymemset(msgReport->sign, 0, sizeof(msgReport->sign));
	{
		u32 inSignal = Frm_GetSignalGroup();
		msgReport->sign[0] = LOBYTEL(inSignal);
		msgReport->sign[1] = HIBYTEL(inSignal);
	}




展开阅读全文

没有更多推荐了,返回首页