MCQs > IT & Programming > C# > Which of the following is the correct way to convert a Byte Array to a Hexadecimal String, and vice versa?

C# MCQs

Which of the following is the correct way to convert a Byte Array to a Hexadecimal String, and vice versa?

Answer

Correct Answer: static readonly char[] _hexDigits = "0123456789abcdef".ToCharArray(); public static string ToHexString(this byte[] bytes) { char[] digits = new char[bytes.Length * 2]; for (inti = 0; i<bytes.Length; i++) { int d1, d2; d1 = Math.DivRem(bytes[i], 16, out d2); digits[2 * i] = _hexDigits[d1]; digits[2 * i + 1] = _hexDigits[d2]; } return new string(digits); }

Explanation:

Note: This Question is unanswered, help us to find answer for this one

C# Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

C# Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it