位元組數組和字串按十六進位互相轉換

來源:互聯網
上載者:User

Private   Function   Byte2HexStr(bt()   As   Byte)   As   String
Dim   btLen       As   Integer
Dim   I               As   Integer
Dim   strDes     As   String
        btLen   =   UBound(bt)   +   1
        strDes   =   Space$(btLen   *   2)
        For   I   =   0   To   btLen   -   1
                Mid$(strDes,   I   +   I   +   1,   2)   =   Right$( "0 "   &   Hex$(bt(I)),   2)
        Next   I
        Byte2HexStr   =   strDes
End   Function

Private   Function   HexStr2Byte(strSrc   As   String)   As   Byte()
Dim   strLen             As   Integer
Dim   btLen               As   Integer
Dim   I                       As   Integer
Dim   bt()                 As   Byte
        strLen   =   Len(strSrc)
        btLen   =   strLen   /   2
        ReDim   bt(btLen   -   1)
        For   I   =   0   To   btLen   -   1
                bt(I)   =   Val( "&H "   &   Mid$(strSrc,   I   +   I   +   1,   2))
        Next   I
        HexStr2Byte   =   bt
End   Function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.