On 10 Feb 2006, at 1:42 am, Bryon Daly wrote:
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.
The networking standard for data is big-endian so if you poke about
in any low level buffers on a little-endian machine at network level
the data might be in the wrong order[1]. Or there's PDP11s and VAXen
and such which mix it up even more. You can have 4321, 1234, 2143,
3412 as bytes in a 32-bit word at machine level.
That's why there's system calls for this stuff :)
It's 15 years since I had to write some modbus stuff on a VAX to
interface with modbus via ethernet and had to deal with this. And the
difference between VAX floats and IEEE floats required some bit-
twiddling...
[1] If any software has anything to do with it. Otherwise it's all
hidden in the chips.
--
William T Goodall
Mail : [EMAIL PROTECTED]
Web : http://www.wtgab.demon.co.uk
Blog : http://radio.weblogs.com/0111221/
Those who study history are doomed to repeat it.
_______________________________________________
http://www.mccmedia.com/mailman/listinfo/brin-l