开发者

Convert int string to hex string

How would I convert a string that represents an integer开发者_如何学JAVA like "4322566" to a hex string?


string s = int.Parse("4322566").ToString("X");


int temp = 0;
string hexOut = string.Empty;
if(int.TryParse(yourIntString, out temp))
{
    hexOut = temp.ToString("X");
}

To handle larger numbers per your comment, written as a method

public static string ConvertToHexString(string intText)
{
    long temp = 0; 
    string hexOut = string.Empty; 
    if(long.TryParse(intText, out temp))
    { 
        hexOut = temp.ToString("X"); 
    } 
    return hexOut;
}


Try .ToString("X").


or .ToString("x") if you prefer lowercase hex.


Try

int otherVar= int.Parse(hexstring ,
System.Globalization.NumberStyles.HexNumber);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜