十六進制與ASCII碼的互轉(C語言)
//函 數 名:CharToHex()
//功能描述:把ASCII字符轉換為16進制
//函數說明:
//調用函數:
//全局變量:
//輸 入:16進制
//返 回:ASCII字符
/**function: CharToHex()
*** ACSII change to 16 hex
*** input:Hex
***Return :ACSII
**/
-
/**function: CharToHex()
-
*** ACSII change to 16 hex
-
*** input:ACSII
-
***Return :Hex
-
**/
-
unsigned char CharToHex(unsigned char bHex)
-
{
-
if((bHex>=0)&&(bHex<=9))
-
{
-
bHex += 0x30;
-
}
-
else if((bHex>=10)&&(bHex<=15))//Capital
-
{
-
bHex += 0x37;
-
}
-
else
-
{
-
bHex = 0xff;
-
}
-
return bHex;
-
}
//函 數 名:HexToChar()
//功能描述:把16進制轉換為ASCII字符
//函數說明:
//調用函數:
//全局變量:
//輸 入:ASCII字符
//返 回:16進制
-
unsigned char HexToChar(unsigned char bChar)
-
{
-
if((bChar>=0x30)&&(bChar<=0x39))
-
{
-
bChar -= 0x30;
-
}
-
else if((bChar>=0x41)&&(bChar<=0x46)) // Capital
-
{
-
bChar -= 0x37;
-
}
-
else if((bChar>=0x61)&&(bChar<=0x66)) //littlecase
-
{
-
bChar -= 0x57;
-
}
-
else
-
{
-
bChar = 0xff;
-
}
-
return bChar;
-
}