ascii字符字库
类似这样
char 0x00
........
........
........
........
........
........
........
........
........
........
........
........
........
........
........
........
char 0x01
........
........
..***...
.*...*..
*.....*.
*.*.*.*.
*.*.*.*.
*.....*.
*.....*.
*.*.*.*.
*..*..*.
.*...*..
..***...
........
........
........
char 0x02
........
........
..***...
.*****..
*******.
**.*.**.
**.*.**.
*******.
*******.
**.*.**.
***.***.
.*****..
..***...
........
........
........
转c语言数组
类似这样:
// char 0x00
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
// char 0x01
0x0,
0x0,
0x38,
0x44,
0x82,
0xaa,
0xaa,
0x82,
0x82,
0xaa,
0x92,
0x44,
0x38,
0x0,
0x0,
0x0,
// char 0x02
0x0,
0x0,
0x38,
0x7c,
0xfe,
0xd6,
0xd6,
0xfe,
0xfe,
0xd6,
0xee,
0x7c,
0x38,
0x0,
0x0,
0x0,
python脚本
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 14 16:34:49 2021
@author: zkai
"""
import string
import os
# 转二进制数字
def convert2Num( str ):
ret = "0";
for c in str:
if c == '.':
ret += '0';
if c == '*':
ret += '1';
return int(ret, 2);
file = open("hankaku.txt")
outFile = open('out.txt', 'w+')
for line in file:
if "char" in line:
print("// " + line.replace("\n", ""));
outFile.writelines(" // " + line.replace("\n", "") + "\n");
if "." in line or "*" in line:
num = convert2Num(line);
hexStr = hex(num);
print(hexStr);
outFile.writelines(" " + hexStr + "," + "\n");
file.close()
outFile.close();
网友评论