C# 十進位數字陣列(0~255)轉十六進位CSV字串(00~FF)
C# 十進位數字陣列(0~255)轉十六進位 CSV字串(00~FF)
程式碼:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CS_Ten2Hex { class Program { static void pause()//C# 命令模式 等待/暫停 pause { Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } static void Main(string[] args) { int[] intData = {1, 2, 4, 8, 16, 32, 64, 128, (256-1)}; String StrData = ""; for (int i = 0; i < intData.Length; i++) { StrData += Convert.ToString(intData[i], 16).ToUpper().PadLeft(2, '0'); if (i < (intData.Length - 1)) { StrData += ","; } } Console.WriteLine(StrData); pause(); } } }
One thought on “C# 十進位數字陣列(0~255)轉十六進位CSV字串(00~FF)”
C# BYTE陣列資料 變成 16進制/十六進制 字串 顯示
String StrAns=””;
for (int i = 0; i < cardSN.Length; i++)//顯示16進制資料
{
if(i==0)
{
StrAns += Convert.ToString(cardSN[i], 16).ToUpper().PadLeft(2, '0');
}
else
{
StrAns += " "+ Convert.ToString(cardSN[i], 16).ToUpper().PadLeft(2, '0');
}
}