Because the code was written in C#, it requires explicitly type cast. For different language, you need modify a little bit, e.g. you need implement your own PadLeft function.
string GetHexString(int num)
{
string ret = "";
while (true)
{
ret = GetSignleHex(num % 16) + ret;
num >>= 4;
// Or num /= 16;
if (num == 0) return ret.PadLeft(4, '0');
}
}
string GetSignleHex(int num)
{
if (num < 10)
{
return num.ToString();
}
else
{
char c = 'A';
c += (char)(num - 10);
return c.ToString();
}
}
HTH
string GetHexString(int num)
{
string ret = "";
while (true)
{
ret = GetSignleHex(num % 16) + ret;
num >>= 4;
// Or num /= 16;
if (num == 0) return ret.PadLeft(4, '0');
}
}
string GetSignleHex(int num)
{
if (num < 10)
{
return num.ToString();
}
else
{
char c = 'A';
c += (char)(num - 10);
return c.ToString();
}
}
HTH