How do I convert a Hexidecimal string to a Byte Array?

11,981

Split the string and parse the hexadecimal numbers:

Dim bytes As Byte() = input.Split("-"c).Select(Function(n) Convert.ToByte(Convert.ToInt32(n, 16))).ToArray()
Share:
11,981

Related videos on Youtube

user2089227
Author by

user2089227

Updated on July 12, 2022

Comments

  • user2089227
    user2089227 almost 2 years

    I have a string representing a hexidecimal value: "46-C9-08-B6-E8-F3-47-CF-53-2A-77-02-C9-19-7F"

    I want to convert this to a byte array so it looks something like this: {&H46, &HC9, &H8, &HB6, &HE8, &HF3, &H47, &HCF, &H53, &H2A, &H77, &H2, &HC9, &H19, &H7F}

    How do I do this?

  • user2089227
    user2089227 about 11 years
    If you could explain this a bit more in depth as im new to this I would appreciate it. The word "Input" gets underlined when I paste this code.
  • OneFineDay
    OneFineDay about 11 years
    input is a string holding your value you want to convert.