Re: How to determine the way data is stored in memory?
- From: "Rod Pemberton" <dont_have@xxxxxxxxxxxxx>
- Date: Sun, 22 Jan 2006 20:28:23 GMT
"Abhishek" <abhisheksgumadi@xxxxxxxxx> wrote in message
news:1137952362.943466.83820@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> lets consider that I have defined an integer like this.
> int a=5;
> now taking the fact that an integer is allocated 2 bytes in memory and
> the memory address increases in the left to right direction, which way
> is the 16bit representationof 5 stored..
> i.e 15 is 0000000000001111 representation in binary right? if the
> memory address increases in left to right direction with each memory
> address being capable of holding 8bits (i.e 1 byte)..can u tellme the
> structure in which it is stored..is it like this???
> 00 00 00 00 00 00 11 11
> ^lesser address ^greater address.
> or is it in different format?
> Please elaborate.
> Thank you very much for ur patience.
> Bye
There are two common methods that I know of for determining endianess.
These can be extended to show the actual ordering.
1) using casts, get the char at the address of an int set to one(1), if it's
one then it's little endian
int x=1;
if((*(char*)&x)==1) {/* little endian */ }
2) setup a union with a long and char types, set the long to one(1), if the
low char is one the it's little endian
union {long Long; char Char[sizeof(long)]} u;
u.Long=1;
if(u.Char[0]==1) {/* little endian */}
The second case could be extended to show you the exact ordering by spitting
out the other values of Char[].
Rod Pemberton
.
- References:
- How to determine the way data is stored in memory?
- From: Abhishek
- How to determine the way data is stored in memory?
- Prev by Date: Re: Runtime Structure Creation
- Next by Date: Re: Test message - PLEASE IGNORE
- Previous by thread: Re: How to determine the way data is stored in memory?
- Next by thread: Endianness (again)
- Index(es):
Relevant Pages
|