//函 數 名:CharToHex()
//功能描述:把ASCII字符轉換為16進制
//函數說明:
//調用函數:
//全局變量:
//輸 入:ASCII字符
//返 回:16進制
/////////////////////////////////////////////////////////////////////
unsigned char CharToHex(unsigned char bHex){
if((bHex>=0)&&(bHex<=9))
bHex += 0x30;
else if((bHex>=10)&&(bHex<=15))//大寫字母
bHex += 0x37;
else bHex = 0xff;
return bHex;
}
/////////////////////////////////////////////////////////////////////
//函 數 名:HexToChar()
//功能描述:把16進制轉換為ASCII字符
//函數說明:
//調用函數:
//全局變量:
//輸 入:16進制
//返 回:ASCII字符
/////////////////////////////////////////////////////////////////////
unsigned char HexToChar(unsigned char bChar){
if((bChar>=0x30)&&(bChar<=0x39))
bChar -= 0x30;
else if((bChar>=0x41)&&(bChar<=0x46))//大寫字母
bChar -= 0x37;
else if((bChar>=0x61)&&(bChar<=0x66))//小寫字母
bChar -= 0x57;
else bChar = 0xff;
return bChar;
字符轉ASCII碼,ASCII碼轉字符
public static int Asc(string character)
{
if (character.Length == 1)
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
return (intAsciiCode);
}
else
{
throw new Exception("Character is not valid.");
}
}
ASCII碼轉字符:
public static string Chr(int asciiCode)
{
if (asciiCode >= 0 && asciiCode <= 255)
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
byte[] byteArray = new byte[] { (byte)asciiCode };
string strCharacter = asciiEncoding.GetString(byteArray);
return (strCharacter);
}
else
{
throw new Exception("ASCII Code is not valid.");
}
} 
JS中把字符轉成ASCII值的函數示例代碼
<script>
str="A";
code = str.charCodeAt();
str2 = String.fromCharCode(code);
str3 = String.fromCharCode(0x60+26); document.write(code+'<br />');
document.write(str2+'<br />');
document.write(str3);
</script>
一、將字符串轉換成ASCII碼
格式: Asc(x)
功能:返回字符串x中第一個字符的ASCII碼。
說明:
◆ x是一個字符串型數據,函數值返回一個。
例如:
x=Asc''0'' 'x的值為48
x=Asc''ABC'' 'x的值為65
二、將ASCII碼轉換成字符
格式:Chr(x)
功能:將ASCII碼值轉換成相應的字符。
說明:
◆ x是一個ASCII碼代碼值,函數值返回一個字符。
例如:
x=Chr(66) 'x的值為字符''B''
toascii將字符轉換為ASCII碼
toascii將字符轉換為ASCII碼
