0

I need to convert a hex string ( received from a game server via socket ), to ascii ( or any other format that works I guess ).

The problem I'm having is that every time I try to display the converted string, it's null, however, this website: Click! works just fine in converting it.

Example Hex received from the server:

008300DD0676657273696F6E3D25326674672532662B53746174696F6E2B3133266D6F64653D736563726574267265737061776E3D3026656E7465723D3126766F74653D302661693D3126686F7374266163746976655F706C61796572733D3026706C61796572733D3132267265766973696F6E3D64666639623862646165323234613332366364313166643566353431326638346463643565346237267265766973696F6E5F646174653D323031342D30382D32322661646D696E733D302667616D6573746174653D31266D61705F6E616D653D4D65746153746174696F6E00

I tried numerous approaches: this is the one I'm currently using:

        public static string Hex2Ascii(string hexString){
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < hexString.Length; i += 2)
        {
            string hs = hexString.Substring(i, 2);
            sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
        }

        return sb.ToString();
    }

Expected result is something like this:

ƒÝversion=%2ftg%2f+Station+13&mode=secret&respawn=0&enter=1&vote=0&ai=1&host&active_players=0&players=12&revision=dff9b8bdae224a326cd11fd5f5412f84dcd5e4b7&revision_date=2014-08-22&admins=0&gamestate=1&map_name=MetaStation
1
  • 1
    How 'bout you show us the code you're using to try to convert it? What do you expect the output to be? Commented Sep 19, 2014 at 4:49

1 Answer 1

1

Your example string seems to have a null-char first, which will terminate your string before it has even started. If you remove the "008300"-prefix from your input, it seems to be working.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.