tags: tgirc早修book

ASCII

全名為 American Standard Code for Information Interchange,美國資訊交換標準代碼
ASCII 維基百科

對應範圍

  • 0~32 號、第 127 號(共 34 種):
    通訊專用或控制字元(LF換行、DEL刪除等)
  • 33~126 號(共 94 個):
    可顯示字元
  • 48~57 號:
    0~9 的阿拉伯數字
  • 65~90 號:
    大寫英文字母
  • 97~122 號:
    小寫英文字母
  • 其他:
    標點符號、運算符號等

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

字元與ASCII碼的操作

運用以下程式碼即可知道 a 的 ASCII 編號為多少:

#include <iostream> using namespace std; int main(){ char c='a'; //宣告字元變數c,並賦予初始值為字母'a' //此時c的值為'a' cout<<c<<" : "<<int(c)<<"\n"; //int(c):將c的值'a',以整數型態輸出 //也就是輸出'a'的ASCII碼97 return 0; }

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

也可從 ASCII 編號轉換成字元,以及運用加減法改變字元值

#include <iostream> using namespace std; int main(){ int c=97; //宣告整數變數c,並賦予初始值97 cout<<c<<" : "<<char(c)<<"\n"; //char(c):將c的值97,以字元型態輸出 //也就是輸出ASCII碼中,97所代表的字元'a' char C='a'; //宣告字元變數C,並賦予初始值為字母'a' //注意,名稱大小寫不同即視為不同變數,所以C跟c是不一樣的! cout<<C<<" - 31 = "<<char(C-31)<<"\n"; //char(C-31):將C的ASCII碼減掉31的值,以字元型態輸出 //'a'的ASCII碼為97,減掉31為66,代表'B' //也就是輸出ASCII碼中,66代表的字元'B' return 0; }

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →