On Oct 15, 11:35*pm, Richard Damon <news.x.richardda...@xoxy.net>
wrote:
> On 10/15/11 3:00 PM, someone wrote:
==
> > I'm stuck...
>
> > And what about big endian / little endian? I'm confused. Looking
> > forward to hear from you!
>
> First, what is the first byte in the file? you are saying that you are
> expecting it to be 72 but you are getting 49. Have you looked at the file..
Good point. The first four bytes of the input file has the values:
[048h 00h 00h 00h] (hexadecimal, I used a hex editor to see this). And
0x48H = 72 decimal... I don't even know if this is little endian or
not, but what I find very strange is the number 49 then... That number
makes no sense to me (why is it adding 1, if it's printing the number
in hexadecimal? What's it thinking?)..?
> Next you talk about getting R1begin which should be 4 bytes, but you are
> setting it to the value of the first byte of the file (memblock[0] is
> the first byte of the file) the static_cast to int is unneeded, as char
> will convert to int implicitly.
Oops, sorry. You're right. I should take the first 4 bytes and convert
them into the correct integer format (which I think is unsigned int
32, but I'll have to test it). However, I still don't know exactly how
to do the conversion, sorry, I'm a bit unexperienced and it took quite
some hours to produce the first code in the original post
> Lastly, you are saying that you are expecting to read 72 bytes at the
> beginning of the file, and also that you are expecting to get the value
> 72 from the beginning of the file, implying that R1begin is a byte count
> for the record, but then don't describe the record format depending on
Exactly.
> that value at all, and then only look at 1 byte for that info, when you
> describe it as a 4 byte number.
You're right. I gave up on the last and concluded that I needed some
help. I was trying to get inspired by some template<T>-code I found.
However that code only worked for reading directly from the file and
now I copied the whole file into memory, in a buffer... The correct
thing to do, is to take out the first 4 bytes and then convert that
into the relevant type. I'm currently struggling with that.
> If R1_begin ins't a data length field, why are you expecting it to have
> the value 72?
You're completely right. It is the data length field and I expect to
read in the value of 72 because: Total bytes read = 4+24+40+4 = 72
bytes. You don't happen to have some genius template that works for
this kind of problem, do you?
I'm sorry, but I still don't get the right value of 72. Here are 2 new
attempts, and I don't quite understand the output:
int R1_begin;
R1_begin = *(reinterpret_cast<char*> (&memblock));
cout << "Value = " << R1_begin << endl; // writes out: Value = 96 ??
why ?
int R1_begin; // makes no difference if I write unsigned int
R1_begin here!
memcpy(&R1_begin, &memblock[0], sizeof(R1_begin));
cout << "Value = " << R1_begin << endl; // writes out: Value =
875770417 ?? why ?
Once I get understand this and get it right, I'll look into the endian-
thing (I'm still not sure whether I have an endian problem or not)...