skip to Main Content

I have GUID Hex, example: ac865c7313e3e347b6c93c9da39ee2c7
I need to bring him to byte[16].
How can I do that?

Guid.ToByteArray() – Not suitable because "-" is taken into account there

2

Answers


  1. Do it in two steps,

    1. Parse your hex GUID into Guid

      //This step is missing in your question.
      var guid = Guid.Parse("ac865c7313e3e347b6c93c9da39ee2c7");
      
    2. Now Convert into Byte[]

      var bytes = guid.ToByteArray();

    Try here

    Login or Signup to reply.
  2. Just insert the dashes in place by doing this:

    string guidStringFixed = guidHexString.Insert(20, "-").Insert(16, "-").Insert(12, "-").Insert(8, "-");

    Then you can parse string to Guid and convert Guid to byte array

    Guid guid = Guid.Parse(guidStringFixed);
    byte[] byteArray = guid.ToByteArray();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search