I use in my C++/CLI project ToBase64String
to give a string like /MnwRx7kRZEQBxLZEkXndA==
I want to convert this string to Hexadecimal representation, How I can do that in C++/CLI or C#?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
FromBase64String will take the string
to byte
s
byte[] bytes = Convert.FromBase64String(string s);
Then, BitConverter.ToString()
will convert a byte array to a hex string ( byte[] to hex string )
string hex = BitConverter.ToString(data);
回答2:
Convert the string to a byte array and then do a byte to hex conversion
string stringToConvert = "/MnwRx7kRZEQBxLZEkXndA==";
byte[] convertedByte = Encoding.Unicode.GetBytes(stringToConvert);
string hex = BitConverter.ToString(convertedByte);
Console.WriteLine(hex);