日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

汉字区位码---非常浅显的知识点

發布時間:2023/12/14 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 汉字区位码---非常浅显的知识点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

國標 GB2312-80 全部漢字與圖形符號排列成 94×94 的一張大表,每一行稱為一個“區”(01 區 ~ 94 區),每一列稱為一個“位”(01 位 ~ 94 位)。

區\位 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 … 94
01   、 。 · ˉ ˇ ¨ 〃 ‘ ’ “ ” 〔 〕 〈 … 〓
… … … … … … … … … … … … … … … … … …
16 啊 阿 埃 挨 哎 唉 哀 皚 癌 藹 矮 艾 礙 愛 隘 … 剝
17 薄 雹 保 堡 飽 寶 抱 報 暴 豹 鮑 爆 杯 碑 悲 … 炳
18 病 并 玻 菠 播 撥 缽 波 博 勃 搏 鉑 箔 伯 帛 … 猖
19 場 嘗 常 長 償 腸 廠 敞 暢 唱 倡 超 抄 鈔 朝 … 楚
20 礎 儲 矗 搐 觸 處 揣 川 穿 椽 傳 船 喘 串 瘡 … 逮
21 怠 耽 擔 丹 單 鄲 撣 膽 旦 氮 但 憚 淡 誕 彈 … 疊
22 丁 盯 叮 釘 頂 鼎 錠 定 訂 丟 東 冬 董 懂 動 … 二
23 貳 發 罰 筏 伐 乏 閥 法 琺 藩 帆 番 翻 樊 礬 … 服
24 浮 涪 福 袱 弗 甫 撫 輔 俯 釜 斧 脯 腑 府 腐 … 羹
… … … … … … … … … … … … … … … … … …
94                                  
漢字的機內碼由高、低字節兩個字節組成,它們分別是區碼和位碼加 160 得到的。即:

高字節 = 區碼 + 160
低字節 = 位碼 + 160
·············································································································································
1、輸入漢字的代碼,使得輸出為漢字。

#include<stdio.h>int main() {char high,low;int code;scanf("%d",&code);high = code / 100 + 160;low = code %100 + 160 ;printf("%c%c",high,low);return 0; }


···································································································································································

2、輸入漢字 求其漢字代碼

#include<stdio.h>int main() {unsigned char high,low;int code;scanf("%c%c",&high,&low); code = (high - 160) * 100 + low - 160;printf("%04d\n",code);return 0; }


有兩處需要注意的關鍵點:
i.定義high,low 要用unsigned char ,即使數據類型如int不加unsigned 默認是signed, 但是對插入類型沒有標準的規定。

ii.printf("%04d\n",code);
其中的“04”不可去,這句話是:code不足四位前面補0,防止區碼為0x(01,02······)的數錯亂。

區號和位號分別加上160,再分別轉換成十六進制數,就成為四位的十六進制GB2312國家標準編碼(簡稱國標碼)。

····································································································································································

#include<iostream> using namespace std;int main() {char a[4];char high,low;int i;for(i = 0 ; i < 4 ; i ++){cin>>a[i];}for(i = 0 ; i < 4 ; i ++){switch(a[i]){case '0':a[i] = 0;break;case '1':a[i] = 1;break;case '2':a[i] = 2;break;case '3':a[i] = 3;break;case '4':a[i] = 4;break;case '5':a[i] = 5;break;case '6':a[i] = 6;break;case '7':a[i] = 7;break;case '8':a[i] = 8;break;case '9':a[i] = 9;break;case 'a':a[i] = 10;break;case 'b':a[i] = 11;break;case 'c':a[i] = 12;break;case 'd':a[i] = 13;break;case 'e':a[i] = 14;break;case 'f':a[i] = 15;break;default:break;}}for(int j = 0 ; j < 2 ; j ++){high = a[j] * 16 + a[++j];}for(int j = 2 ; j < 4 ; j ++){low = a[j] * 16 + a[++j];}putchar(high);putchar(low);return 0; }


·································································································································································

#include<iostream> #include<stdio.h> using namespace std;struct{int temp1;int temp2; }a[2]; int main() {int i;unsigned char high,low;scanf("%c%c", &high , &low);//high = 176 low = 174 轉為十六進制 //printf("%d %d",high,low);char a[4] = {'a','b','c','d'};int b[4];b[0] = high / 16;//11b[1] = high % 16;//0b[2] = low / 16;//10b[3] = low % 16;//14for(i = 0 ; i < 4 ; i ++){switch(b[i]){case 0:a[i] = '0';break;case 1:a[i] = '1';break;case 2:a[i] = '2';break;case 3:a[i] = '3';break;case 4:a[i] = '4';break;case 5:a[i] = '5';break;case 6:a[i] = '6';break;case 7:a[i] = '7';break;case 8:a[i] = '8';break;case 9:a[i] = '9';break;case 10:a[i] = 'a';break;case 11:a[i] =' b';break;case 12:a[i] = 'c';break;case 13:a[i] = 'd';break;case 14:a[i] = 'e';break;case 15:a[i] = 'f';break;} }for(i = 0 ; i < 4 ; i ++){printf("%c",a[i]);}cout<<endl;return 0; }

總結

以上是生活随笔為你收集整理的汉字区位码---非常浅显的知识点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。