Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 826533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:25:45+00:00 2026-05-15T03:25:45+00:00

I read about Endianness and understood squat… so I wrote this main() { int

  • 0

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"<<endl;

    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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:25:46+00:00Added an answer on May 15, 2026 at 3:25 am

    Endianness, as you discovered by your experiment refers to the order that bytes are stored in an object.

    Bits do not get stored differently, they’re always 8 bits, and always “human readable” (high->low).

    Now that we’ve discussed that you don’t need your code… About your code:

    for(int i=0;i<32;i++)
    {   
      temp = *( (bool*)ptr + i );
      ...
    }
    

    This isn’t doing what you think it’s doing. You’re iterating over 0-32, the number of bits in a word – good. But your temp assignment is all wrong 🙂

    It’s important to note that a bool* is the same size as an int* is the same size as a BigStruct*. All pointers on the same machine are the same size – 32bits on a 32bit machine, 64bits on a 64bit machine.

    ptr + i is adding i bytes to the ptr address. When i>3, you’re reading a whole new word… this could possibly cause a segfault.

    What you want to use is bit-masks. Something like this should work:

    for (int i = 0; i < 32; i++) {
      unsigned int mask = 1 << i;
      bool bit_is_one = static_cast<unsigned int>(ptr) & mask;
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Read about the issue in this stackoverflow question . Still have the same issue
I read about this question on referencing one project into another and this question
Read this question today about safe and unsafe code I then read about it
I read about push notification in Windows Phone 7 . I could use this
I read about __packed__ from here and, I understood that when __packed__ is used
I read about implicit conversions being done between different value class types. The book
I read about conversion of ASCII to EBCDIC using this link; Convert String from
I read about this problem for the iPhone on the post here . The
I read about this from Effective c++ ,this is Col.10. It say it's a
I read about JavaScript closures and I thought that I understood it, but apparently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.