Tcl中binary format 和binary scan命令分析.docVIP

  1. 1、本文档共3页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Tcl中binary format 和binary scan命令分析

Tcl中binary format 和binary scan命令分析 Tcl中,用binary format 和binary scan来处理二进制文件用得比较多,但这个两个命令比较难理解。我花了一天的时间,终于略知一二。现和大家分享下。 一:binary命令的解释 binary format binary scan ? 帮助给出的解释: This command provides facilities for manipulating binary data. The first form, binary format, creates a binary string from normal Tcl values. For example, given the values 16 and 22, on a 32-bit architecture, it might produce an 8-byte binary string consisting of two 4-byte integers, one for each of the numbers. The second form of the command, binary scan, does the opposite: it extracts data from a binary string and returns it as ordinary Tcl string values. 大意是:该命令是对二进制数据进行操作。binary format命令,是把普通的Tcl 数据转换成二进制字符,例如:在32位的机器上,可以把16和22这样的数据,转换成由两个4字节的整数组成的8字节的二进制字符串(一个二进制字符的显示图形,是由字符编码方式决定的,在记事本里有ANSI、Unicode、Unicode big endian和UTF-8编码方式,关于字符编码可看:字符编码笔记:ASCII,Unicode和UTF-8)。binary scan命令,功能正好与binary format命令相反,是把二进制字符转换成正常的Tcl 数据。 ? 二:binary命令的语法 1.binary format formatString ?arg arg ...? The binary format command generates a binary string whose layout is specified by the formatString and whose contents come from the additional arguments. The resulting binary value is returned binary format命令接收数据(arg arg ...?)并根据模板(formatString)进行压缩转换,最后返回转换的值。 处理不同的数据用不同的模板,比如待处理的数据是二进制数(例:1001010)可用b或B,待处理的数据是十六进制数(例:FF)可用h或H;并根据待处理数据的长度,设置count,比如待处理二进制数1001010长为8,则count=8,(在其它模板中,count还可表示重复特征等)。 ? 2.binary scan string formatString ?varName varName ...? The binary scan command parses fields from a binary string, returning the number of conversions performed. String gives the input bytes to be parsed (one byte per character, and characters not representable as a byte have their high bits chopped) and formatString indicates how to parse it. Each varName gives the name of a variable; when a field is scanned from string the result is assigned to the corresponding variable. Binary scan 命令根据模块(formatString)从一二进制字符里解析获得一数值,并把该数值赋给变量(arg arg ...?),该命令返回解析的字符的个数。 待解析的字符可能是由几个字节组成,到底由几个字节组成一个字符,由通道的属性来决定,比如fconfigure channel

文档评论(0)

yan698698 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档