用@nonsmall 不死猫的binaryToText函数:
- ;Subject:binary conversion to text by lisp 二进制文件转文本
- ;Writen:nonsmall(不死猫)
- ;Date:2009 10 18
- ;All Rights Reserved 版权所有 nonsmall(不死猫)
- ;Contact: QQ:43797405 Email:nonsmall@163.com
- (defun binaryToText(FileName / ADODB.Stream)
- (Setq ADODB.Stream (Vlax-Get-Or-Create-Object "ADODB.Stream" ))
- (Vlax-Put-Property ADODB.Stream 'Type 1 )
- (Vlax-Invoke ADODB.Stream 'Open )
- (Vlax-Invoke-Method ADODB.Stream 'LoadFromFile FileName )
- (Vlax-Put-Property ADODB.Stream 'Position 0 )
- (Vlax-Invoke-Method ADODB.Stream 'Write (car (list (Vlax-Invoke-Method ADODB.Stream 'Read (Vlax-Get ADODB.Stream 'Size )) (Vlax-Put-Property ADODB.Stream 'Position 0 ))))
- (Vlax-Put-Property ADODB.Stream 'Position 0 )
- (Vlax-Put-Property ADODB.Stream 'Type 2 )
- (Vlax-Put-Property ADODB.Stream 'CharSet "us-ascii" )
- (Vlax-Invoke ADODB.Stream 'ReadText)
- ;(vlax-release-object ADODB.Stream)
- )
- (setq data (binaryToText (setq filename (getfiled "" (if filename filename "") "" 8))))
- (setq lst1 nil)
- (setq i 1)
- (repeat 20
- (setq num1 (ascii (substr data i 1)))
- (setq num2 (ascii (substr data (+ i 1) 1)))
-
- (setq num (+ num1 (* 256 num2)))
- (if (> num 32767)
- (setq num (- num 65536))
- ) ;_ if
- (setq lst1 (append lst1 (list num)))
- (setq i (+ i 2))
- )
lst1返回:(4 0 1344 2372 2372 12288 4 32627 32623 32621 32608 32627 32623 32621 32608 32627 32623 32621 32608 32627)
用@baitang36 的syz-read-bin函数:
- (vl-load-com)
- (or syz-read-bin (load (setq sysname (getfiled "" (if sysname sysname "") "" 8))))
- (setq fi (open (getfiled "" (if filename filename "") "" 8) "r"))
- (setq data2 (syz-read-bin 8000000 fi))
- (close fi)
- (setq i 1)
- (setq lst2 nil)
- (repeat 20
- (setq num1 (ascii (substr data2 i 1)))
- (setq num2 (ascii (substr data2 (+ i 1) 1)))
- (setq num (+ num1 (* 256 num2)))
- (if (> num 32767)
- (setq num (- num 65536))
- ) ;_ if
- (setq lst2 (append lst2 (list num)))
- (setq i (+ i 2))
- )
lst2返回:(4 0 2368 2500 2500 12288 4 -4161 -8040 3087 5218 -4473 -8496 2454 6658 -4680 -7774 1923 7499 -4707)
lst2和Matlab的一致,
请问@nonsmall 不死猫的binaryToText函数要怎么用?
还有,@baitang36 的syz-read-bin函数能给源码吗? |