zoukankan      html  css  js  c++  java
  • HEX2BIN

    第一种方法:

    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
    
  • 相关阅读:
    P4370[Code+#4]组合数问题2【数学,堆】
    牛客挑战赛53G同源数组(Easy Version)【NTT】
    P3577[POI2014]TURTourism【状压dp】
    P1232[NOI2013]树的计数【思维】
    AS3 CookBook学习整理(十一)
    AS3 CookBook学习整理(十五)
    AS3 CookBook学习整理(十四)
    AS3 CookBook学习整理(十二)
    AS3 CookBook学习整理(八)
    AS3 CookBook学习整理(十六)
  • 原文地址:https://www.cnblogs.com/zpchcbd/p/12099554.html
Copyright © 2011-2022 走看看