Conversion between Base64String and Hexadecimal

谁说我不能喝 提交于 2019-11-27 18:31:00

问题


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 bytes

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(bytes);



回答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);


来源:https://stackoverflow.com/questions/7784345/conversion-between-base64string-and-hexadecimal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!