需要将ascii值转换为hex值

我需要将ascii转换为hex值。 请参阅Ascii表,但我有几个例子如下:

  • ascii 1 = 31
  • 2 = 32
  • 3 = 33
  • 4 = 34
  • 5 = 35
  • A = 41
  • a = 61等

但我使用的是int而不是字符串值。 有可能做到这一点。 因此int test = 12345; 需要获得转换后的i = 3132333435

将Char转换为ASCII

 int c = (int)'a'; 

Similair对Anthony Pegram的解决方案,但更多LINQ’ish和更短,但在聚合方法中多个字符串分配的速度较慢。

 string hex = input.Select(c => ((int)c).ToString("X")).Aggregate((a, s) => a + s);