how is data stored at bit level according to "Endianness" ?

Posted by bakra on Stack Overflow See other posts from Stack Overflow or by bakra
Published on 2010-05-28T20:38:37Z Indexed on 2010/05/28 20:42 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

I read about Endianness and understood squat...

so I wrote this

main() { int k = 0xA5B9BF9F;

BYTE *b = (BYTE*)&k;    //value at *b is 9f
b++;    //value at *b is BF
b++;    //value at *b is B9
b++;    //value at *b is A5

}

k was equal to "A5 B9 BF 9F"

and (byte)pointer "walk" o/p was "9F BF b9 A5"

so I get it bytes are stored backwards...ok.

~

so now I thought how is it stored at BIT level...

I means is "9f"(1001 1111) stored as "f9"(1111 1001)?

so I wrote this


int _tmain(int argc, _TCHAR* argv[])
{
    int k = 0xA5B9BF9F;
    void *ptr = &k;
    bool temp= TRUE;
    cout<<"ready or not here I come \n"<

    for(int i=0;i<32;i++)
{   
    temp = *( (bool*)ptr + i );
    if( temp )
        cout<<"1 ";
    if( !temp)
        cout<<"0 ";
    if(i==7||i==15||i==23)
        cout<<" - ";
}

}

I get some random output

even for nos. like "32" I dont get anything sensible.

why ?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointer