123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|381|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> On Topic -> Number conversion!!

Sun, 05 Jul 2009, 16:03
Afr0
Right.
I'm trying to read a UInt32 from a file (unsigned integer).

The format of the file is as follows:



I'm having problems when reading the length of the string. It always comes out as some ridiculously long number, so that when I try to read the string itself (as a sequence of chars), I run out of system memory.

Here are the conversions I tried:

- Converting to a big-endian number.
- Converting from a hexadecimal base (which, according to the debugger made the number equal to 20, but the program still crashed saying 'Value was either too large or too small for a UInt32.').

I also tried reading the number as a byte array, and converting it using the following method:



It didn't work.

Here's my current code:



If it helps, I know the resulting string is supposed to be 14 characters long (because I can see it in the debugger).
If anyone has any more ways to convert the number, please help!

Edit: When reading the number as a 'straight' uint without any conversion, it's value reads in the debugger as 855244800.

Edit: No, I never read Instinct's tutorial(s) about converting numbers. Because I haven't had time and because I probably wouldn't understand it (I have Dyscalculia).


-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 05 Jul 2009, 17:20
Jayenkai
If you feel like posting a small sample of the data, that might help..
Too tired to work it out code-wise, but I could probably do a hack-away at it!

-=-=-
''Load, Next List!''
Sun, 05 Jul 2009, 18:40
Evil Roy Ferguso
Have you confirmed that the length is being written correctly? It would be nice to see how you are writing that.

Once you know the values are being written correctly, try writing a test. Write out some small test files with known values (including some edge cases like 0 and 1), then read and assert that the number you've read back in is the one you've written (Assert.AreEqual). You don't need to read anything other than the number until you've confirmed that those are being written/read correctly.

I really doubt you need to mess with Endianness or Hex or reading the individual bytes -- check out MSDN's sample code for reading/writing binary data. You'll probably want .ReadUInt32().
Mon, 06 Jul 2009, 00:31
Afr0
@Evil Roy: I didn't write the archive I'm reading. I am merely reading it.

@Jay: Linky

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!