On 2/9/06, The Fool <[EMAIL PROTECTED]> wrote:
>
> So I needed to create C++ class that would be used to create a static
> copy of some data the program already Uses (but sometimes changes), for
> which it would need to revert to its original state (it also non
> contiguous).  It also needs to be able to 'fiddle' with the data at the
> byte/bit level.
>
> So I create part of the class, but when I tested it I got these weird
> results.  It seemed to be putting say integer (32bit) data bytes
> backwards..


Sounds like an endian issue to me.  Are you on a PC?  Pentiums are little
endian, so the LSByte is written first (ie: to the lowest address).  Let's
say you want to write the 32-bit hex integer value  0x76543210 to address
0.
Most Significant Byte:  0x76
Least Significant Byte: 0x10

Address    Byte
-----------------------
000000      0x10
000001      0x32
000002      0x54
000003      0x76

When the CPU reads an integer (or other 4-byte value), it
automatically arranges the bytes around so they are MSB..LSB in the
processor and the endian-ness is transparent to the user.  But if you
manipulate the individual bytes of a multi-byte value, you need to be aware
of the endianness of the machine and deal with it accordingly.

Now imagine the headaches when you have little endian hardware sharing raw
data buffers with big endian hardware and welcome to my world.  :-)

I tried to be concise here - let me know if you want further elaboration.

-Bryon

Also, IIRC, a while back I posted the origin article of the big/little
endian terms: "On Holy Wars and a Plea For Peace" if you're interested.
_______________________________________________
http://www.mccmedia.com/mailman/listinfo/brin-l

Reply via email to