码迷,mamicode.com
首页 > 其他好文 > 详细

HEX2BIN

时间:2019-12-26 00:08:49      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:tin   XML   xmldom   and   ros   方法   pac   als   crlf   

第一种方法:

php -r "echo bin2hex(file_get_contents('x.bin'));" >>hex.txt
php -r "echo pack('H*',file_get_contents('hex.txt'));" >>x.bin

第二种方法:

Set fso=createobject("scripting.filesystemobject")
if wscript.arguments.count<>1 then 
        wscript.echo "用法1:将文件拖到我身上!"&vbcrlf & "用法2:HBH.vbs ""filepath"" !"
        wscript.quit
else
        if fso.fileexists(wscript.arguments(0))=false then 
        wscript.echo " 目标文件不存在 ":wscript.quit
        end if 
end if


Set file=fso.opentextfile(wscript.arguments(0))
Fdata=file.readall
file.close

Isbin=false
for k=1 to len(Fdata)
        ascii=asc(mid(ucase(Fdata),k,1))
        if (ascii<48 or ascii>70) or (ascii>57 and ascii<65) then 
         Isbin=true
         exit for
        end if
next

if Isbin=true then 
 ok=ReadBin(wscript.arguments(0))          '生成HEX文件                
else
 ok=WriteBin(wscript.arguments(0), Fdata) '生成bin文件
end if

Function ReadBin(FileName)
 Dim Stream, ObjXML, MyNode
 Set ObjXML = CreateObject("Microsoft.XMLDOM")
 Set MyNode = ObjXML.CreateElement("binary")
 Set Stream = CreateObject("ADODB.Stream")
 MyNode.DataType = "bin.hex"
 Stream.Type = 1
 Stream.Open
 Stream.LoadFromFile FileName
 MyNode.NodeTypedValue = Stream.Read
 Stream.Close
fso.opentextfile(FileName & ".txt",2,1).write(MyNode.Text)
 Set MyNode = Nothing
 Set Stream = Nothing
 Set ObjXML = Nothing
End Function

Function WriteBin(FileName, BufferData)
 Dim Stream, ObjXML, MyNode
 Set ObjXML = CreateObject("Microsoft.XMLDOM")
 Set MyNode = ObjXML.CreateElement("binary")
 Set Stream = CreateObject("ADODB.Stream")
 MyNode.DataType = "bin.hex"
 MyNode.Text = BufferData
 Stream.Type = 1
 Stream.Open
 Stream.Write MyNode.NodeTypedValue
 Stream.SaveToFile FileName & ".bin", 2
 Stream.Close
 Set stream = Nothing
 Set MyNode = Nothing
 Set ObjXML = Nothing
End Function

set Fdata=nothing
set fso=nothing

HEX2BIN

标签:tin   XML   xmldom   and   ros   方法   pac   als   crlf   

原文地址:https://www.cnblogs.com/zpchcbd/p/12099554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!