开发者

hexadecimals to integer

I know how to convert hexadecimals to integers when i only have one hexadecimal character. but im getting a string of two characters.

I'm converting both characters to hex with:

String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()))

so then lets say i have 01, and 3f as my two length characters. how am i supposed to convert those to integer? i tried doing

int length = int.Parse("013f", System.Globalization.NumberStyles.AllowHexSpecifier);

but apparently that is incorrect. i even took the values of both of those, Concat'd them together, and then tried to parse them.. that obviously was not right

am i doing something wrong trying to parse these two hexadecimals into a length, or is the server im getting the information from using a non-standard length system. because i can get the correct lengths when the first character is 00, like 0001 or something. im just not sure about when i have two length characters.

EDIT: after some trial and error, the expected value is 491

Update number two开发者_运维百科:

Basically the server provides me with a two character long string, that tells you the length of the following data.

the two characters for this specific attribute are 01, and 3f. the following data is 491 characters long, which as far as i can see, has no relation to 013f what-so-ever, but i know there is one somewhere, because another application is using this exact same data but coming out with the correct results.


It's not really clear what the problem is.

The hex value 0x013F is decimal 319. Your code evaluates this correctly, although I'd use NumberStyles.HexNumber rather than NumberStyles.AllowHexSpecifier:

int length = int.Parse("013f", NumberStyles.HexNumber);

What number are you expecting 0x013F to be converted to?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜