serialization class and endian
- From: ma740988@xxxxxxxxx
- Date: 16 Mar 2006 08:26:54 -0800
For discussion purposes lets integer representation on machine 'X'
is 16-bits. Lets further assume we'll transmit the value is 45 from
machine 'X' to machine 'Y' - whose integer representation is
also 16-bits. Now given:
struct foo
{
unsigned int val;
};
foo f.
f.val = 0x00AD;
Assume a little endian machine. Pictorially this represents:
| 65536 | .... | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 0 1 0 1 1 0 1
Now transmittal of 0xAD from a little endian to a big endian machine
would amount to:
| 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | .... | 65536 |
1 0 1 1 0 1 0 1
on the big endian machine. As a result we end up with 0xAD00.
I've got a serialization class here that needs improvement. I'm told
that if I make everything byte oriented. More precisely, any integer
value is actually written in decimal string (lots of std::string
usage).
The question. I'm not sure if I'm following how this works. How do
you take an integer value, write as a decimal string, transmit it and
reconstruct it to get the right answer of 0x00AD?
I would think that when re-constructed one would still end up with
0xAD00 ( incorrect - endian swapped value ). Perhaps I'm missing
something about the convesion of integer to string representation and
how this solves the endian issue.
Thanks in advance for clarification
.
- Prev by Date: How to write such a Makefile
- Next by Date: Re: function similar to atoi()
- Previous by thread: How to write such a Makefile
- Next by thread: Re: serialization class and endian
- Index(es):