现在的位置: 首页 > 综合 > 正文

byte[] to hex string base64 convert

2013年10月14日 ⁄ 综合 ⁄ 共 413字 ⁄ 字号 评论关闭

There is a built in method for this:

byte[] data = { 1, 2, 4, 8, 16, 32 };

string hex = BitConverter.ToString(data);

Result: 01-02-04-08-10-20

If you want it without the dashes, just remove them:

string hex = BitConverter.ToString(data).Replace("-", string.Empty);

Result: 010204081020

If you want a more compact representation, you can use Base64:

string base64 = Convert.ToBase64String(data);

Result: AQIECBAg

http://stackoverflow.com/questions/623104/byte-to-hex-string

抱歉!评论已关闭.