[独创算法] HotCRC内的HotCodeToHex()源码(菜农自创万国字符编码)

[复制链接]
 楼主| hotpower 发表于 2023-9-23 10:29 | 显示全部楼层 |阅读模式
本帖最后由 hotpower 于 2023-9-23 10:35 编辑

菜农电子淘宝:https://hotcomlock.taobao.com/ 准备出书:http://hotcomlock.com/hotcomlock.html
  1. HotCode汉字编码(V1.0)是菜农对UniCode编码(V5.0)的汉字简化版本:
  2. 1.用0080-00ff替换2580-25ff方块元素几何图形。
  3. 2.用f900-faff替换2c00-2dff格拉哥里字母等。
  4. 3.用fe30-fe4f替换9fc0-9fdf未定义。
  5. 4.用ff00-ffff替换2800-28ff盲文点字模型。
  6. HotCode选中unicode2000-9fff为编码范围,
  7. 然后加6000,使HotCode编码范围为8000-ffff,ascii码为00-7f。
  8. HotCode编码汉字为两字节,字符为单字节。
  1.     function HotCodeToHex(hotcodestr) {
  2.         var str,ptr,hexstr;
  3.         var i, num;
  4.         hexstr = "";
  5.         str = hotcodestr;
  6.         i = 0;
  7.         for(i = 0;i < str.length;i ++) {
  8.             num = str.charCodeAt(i);
  9.             if(num < 0x80) {//字符,.[]-+
  10.                 hexstr += inttohex(num, 2);
  11.             }
  12.             else if(num < 0x100){
  13.                 num -= (0x0080 - 0x2580);//0x80-0x80+2580
  14.                 num += 0x6000;
  15.                 hexstr += inttohex(num, 4);
  16.             }
  17.             else {//汉字
  18.                 if(num >= 0xff00) {//全角ascii,全角中英文标点等
  19.                     num -= (0xff00 - 0x2800);
  20.                 }
  21.                 else if (num >= 0xfe30 && num <= 0xfe4f) {
  22.                     num -= (0xfe30 - 0x9fc0);
  23.                 }
  24.                 else if (num >= 0xf900 && num <= 0xfaff) {
  25.                     num -= (0xf900 - 0x2c00);
  26.                 }
  27.                 else if (num >= 0x2000 && num <= 0x9fff) {
  28.                 }
  29.                 else {
  30.                     num = 0x3000;//空格
  31.                 }
  32.                 num += 0x6000;
  33.                 ptr = inttohex(num, 4);
  34.                 hexstr += ptr;
  35.             }
  36.         }
  37.         return hexstr;
  38.     }

您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

508

粉丝
快速回复 在线客服 返回列表 返回顶部