简体   繁体   中英

Convert String to Byte Array in VB.Net

My aims is to do the following

  1. Convert UNIX Time (ie 1582818012) to HEX String (ie 5E57E2DC) - Solved
  2. Convert HEX String to Byte Array (ie 5E57E2DC) to (ie &H5E, &H57, &HE2, &HDC) - Pending

How can I do the conversion?

So I this case the result will be something like below:

Dim oneByte() As Byte = {&H5E, &H57, &HE2, &HDC}

oneByte(0)= 5E

oneByte(1)= 57

etc...

Using a couple of standard methods

    Dim ut As Integer = 1582818012
    Dim uts As String = Convert.ToString(ut, 16)
    'look at oneByte in hex
    Dim oneByte() As Byte = BitConverter.GetBytes(ut).Reverse.ToArray
    '           (0) &H5E    Byte
    '           (1) &H57    Byte
    '           (2) &HE2    Byte
    '           (3) &HDC    Byte

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM