fork download
  1. #include <iostream>
  2. #include <cstdint> // uint16_t and uint8_t
  3.  
  4. using namespace std;
  5.  
  6. bool isBigEndian(){
  7. uint16_t word = 1; // 0x0001
  8. uint8_t *first_byte = (uint8_t*) &word; // points to the first byte of word
  9. uint8_t ui8 = (uint8_t)word; // points to the first byte of word
  10. cout << to_string(*first_byte) << endl;
  11. cout << to_string(ui8) << endl;
  12. return !(*first_byte); // true if the first byte is zero
  13. }
  14.  
  15. int main(){
  16. cout << (isBigEndian()?"Big-Endian":"Little-Endian") << endl;
  17. return 0;
  18. }
Success #stdin #stdout 0.01s 5296KB
stdin
123
stdout
1
1
Little-Endian