> From: The Fool <[EMAIL PROTECTED]>
> From: Bryon Daly <[EMAIL PROTECTED]>
>
> 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.
>
> ------
> Ok so this is what I've been doing:
>
> int IMem::PutInt(const long PutAt, const int PutMe)
> {
> if ((PutAt * __Int_Size__) <= CurrentSize)
> {
> try //
> {
> *((int *) &Mem[PutAt * __Int_Size__]) = PutMe;
> }
> catch (...)
> {
> Enterprise();
> MessageBox(hiwind,"IMem PutInt Threw an
Exception","REALLY
> bad",MB_OK);
> // Call Panic Save HERE
> Excelsior();
> return No;
> }
>
> return Yes;
> }
> else //
> {
> return No;
> }
> }
>
> But you are telling me I need to create a union / structure fill it
> with the value, manually flip the bytes around and then store it?
>
Like this:
typedef struct _FlipBytes
{
BYTE One;
BYTE Two;
BYTE Tre;
BYTE For;
} FlipBytes;
typedef union _FlipInt
{
int Flip;
FlipBytes Flop;
} FlipInt;
FlipInt Me;
Me.Flip = PutMe;
XorSwap(Me.Flop.For,Me.Flop.One);
XorSwap(Me.Flop.Tre,Me.Flop.Two);
int PutNewMe = Me.Flip;
try //
{
*((int *) &Mem[PutAt * __Int_Size__]) = PutNewMe;
}
_______________________________________________
http://www.mccmedia.com/mailman/listinfo/brin-l