It is necessary to convert from among the array of 4 elements of this type byte [] qwe = {0x00, 0x00, 0x2F, 0xA3}; So far, stopped at

byte[] b1 = BitConverter.GetBytes(hash_ball); // {00, 00, 32, 64} string B_2 = BitConverter.ToString(b1); // 00-00-14-40 

I can not convert an array from this string, and at the same time, there would be 0x before each element.

    1 answer 1

    You confuse a byte with its string representation in a hexadecimal system.

    The first method is correct. The resulting array matches what you need. You just output it in decimal notation rather than in hexadecimal.

    Use to output

     Console.WriteLine("{" + string.Join(", ", qwe.Select(b => $"0x{b:X2}")) + "}"); 
    • Thanks, but I need not to output, but to write to the array byte [] - qweqwe
    • @qweqwe: And the first method is suitable for writing to an array: BitConverter.GetBytes . - VladD
    • And how it will look in the code, I just do not understand - qweqwe
    • @qweqwe: This is how it will look like: byte[] b1 = BitConverter.GetBytes(hash_ball); . - VladD