Да, это отвечает на вопрос. Вот более общий ответ:
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
cout<<"sizeof(char) = "<<sizeof(char)<<endl;
cout<<"sizeof(unsigned int) = "<<sizeof(unsigned int)<<endl;
//NOTE: Windows, Mac OS, and Linux and Tru64 Unix are Little Endian architectures
//Little Endian means the memory value increases as the digit significance increases
//Proof for Windows:
unsigned int x = 0x01020408; //each hexadecimal digit is 4 bits, meaning there are 2
//digits for every byte
char *c = (char *)&x;
unsigned int y = *c*pow(16,0) +pow(16,2) * *(c+1)+pow(16,4) * *(c+2)+pow(16,6) * *(c+3);
//Here's the test: construct the sum y such that we select subsequent bytes of 0x01020408
//in increasing order and then we multiply each by its corresponding significance in
//increasing order. The convention for hexadecimal number definitions is that
//the least significant digit is at the right of the number.
//Finally, if (y==x),then...
if (y==x) cout<<"Little Endian"<<endl;
else cout<<"Big Endian"<<endl;
cout<<(int) *c<<endl;
cout<<(int) *(c+1)<<endl;
cout<<(int) *(c+2)<<endl;
cout<<(int) *(c+3)<<endl;
cout<<"x is "<<x<<endl;
cout<<(int)*c<<"*1 + "<<(int)*(c+1)<<"*16^2 + "<<(int)*(c+2)<<"*16^4 + "<<(int)*(c+3)<<" *16^6 = "<<y<<endl;
system("PAUSE"); //Only include this on a counsel program
return 0;
}
Это отображает
8
4
2
1
для разыменованных значений в c, c + 1, c + 2 и c + 3 соответственно.
Сумма y равна 16909320, что равно x. Несмотря на то, что значение цифр растет справа налево, это все еще Little Endian, потому что соответствующие значения памяти также растут справа налево, поэтому двоичный оператор << сдвига влево << увеличит значение переменной пока ненулевые цифры не будут полностью смещены с переменной. Не путайте этот оператор с оператором << std :: cout.
Если бы это был Big Endian, то отображение для c, c + 1, c + 2 и c + 3 соответственно было бы выглядеть так:
1
2
4
8 </p>