乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > 文字怎么转换成<em>二进制</em>数啊???-二进制 转 word,word文档二进制怎么做

文字怎么转换成<em>二进制</em>数啊???-二进制 转 word,word文档二进制怎么做

作者:乔山办公网日期:

返回目录:word文档


每个字母都对应一个ASCII值,你把对应的ASCII值转成二进制数就行了
A 对应的是65,往后依次加1,一直到Z 90
a 对应的是97,往后依次加1,一直到Z 122

你注意看啊,百科写的很清楚,由于机器只识二进制数,英文等想要机器识别要通过ASCLL码,来转换。汉字,日文,韩文呢也需要一个标准zhidao来转换成二进制让机器识别,这就是:

“1981年,我国国家标准GB2312--80(信息交换用汉字编码字符集——基本集)为6763个常用汉字规定了代码,每个汉字占两个字节,每个字节用八位二进制数来表示。1995年又颁布了《汉字编码扩展规范》(GBK)。GBK与GB2312--80国家标准所对应的内容标准兼容,同时,在字汇一级支持ISO/IEC10646--1和GB13000--1的全部中、日、韩(CJK)汉字,共计20902字。把文字、图形、图象、声音、动画等信息,变成按一定规则编码的二进制数,这就是信息的数字化。”
public class Test01 {
public static void main(String[] args) {

//比如我现在要转这个字符
String str = "Hello World";

//先把他变为字符数
char[] chs = str.toCharArray();

//然后通过integer中的toBinaryString方法来一个一个转

for (int i = 0; i < chs.length; i++) {
System.out.print(Integer.toBinaryString(chs[i]));
}

}
}

1001000110010111011001101100110111110000010101111101111111001011011001100100

代码 /// ///二进制数据转换e79fa5e98193e78988e69d83330为word文件 /// /// 二进制数据 /// word文件名 /// word保存的相对路径 public string ByteConvertWord(byte[] data, string fileName) { string savePath =@"\SystemWord\"+FormatNowTime(2)+@"\"; if (!System.IO.Directory.Exists(GetPath() + savePath)) { Directory.CreateDirectory(GetPath() + savePath); } savePath += fileName + ".doc"; string filePath = GetPath() + savePath; FileStream fs; if (System.IO.File.Exists(filePath)) { fs = new FileStream(filePath,FileMode.Truncate); } else { fs = new FileStream(filePath,FileMode.CreateNew); } BinaryWriter br = new BinaryWriter(fs); br.Write(data, 0, data.Length); br.Close(); fs.Close(); return savePath; } /// /// word文件转换二进制数据(用于保存数据库) /// /// word文件路径 /// 二进制 private byte[] wordConvertByte(string wordPath) { byte[] bytContent = null; System.IO.FileStream fs = null; System.IO.BinaryReader br = null; try { fs = new FileStream(wordPath,System.IO.FileMode.Open); } catch { } br = new BinaryReader((Stream)fs); bytContent = br.ReadBytes((Int32)fs.Length); return bytContent; } /// ///项目所在目录 /// /// public string GetPath() { return Application.StartupPath; } /// ///格式化当前时间: /// 1:yyMMddHHmmss; 2:yyyy-MM\dd\ /// /// public string FormatNowTime(int num) { if (num == 1) { returnDateTime.Now.ToString("yyMMddHHmmss"); } else if (num == 2) { returnDateTime.Now.ToString("yyyy-MM") + @"\" + DateTime.Now.Day; } return ""; } //测试方法 private void button1_Click(object sender,EventArgs e) { string newWord = ByteConvertWord(wordConvertByte(@"D:\测试文件.doc"),"测试成功"); }

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网