简体   繁体   中英

C# Convert string to hex

I've search around a lot & keep getting a mixture of errors, I'm using a web api to convert some text to numbers (xuid) I then want to convert those numbers to a hexadecimal & keep getting an error saying the value was too large||small for an int32 code--

        WebClient client = new WebClient();
        client.Headers.Add("Content-Type", "text/json");
        client.Headers.Add("X-AUTH", "ce0c28c65911893794ec47af634939b9445d2007");
        await Task.Delay(500);

        var fd = client.DownloadString("https://xboxapi.com/v2/xuid/" + Gamertag.Text);
        int decVal = int.Parse(fd, System.Globalization.NumberStyles.HexNumber);
        Xuid.Text = decVal.ToString();

An int variable holds a number, not a representation of the number. So use

 Xuid.Text = decVal.ToString("X");

For the required output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM