2009-03-12 15:35:35 +00:00
|
|
|
// endian_io_test.cpp ----------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
// Copyright Beman Dawes, 2009
|
|
|
|
|
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
|
|
|
// See http://www.boost.org/LICENSE_1_0.txt
|
|
|
|
|
|
|
|
|
|
// See library home page at http://www.boost.org/libs/endian
|
|
|
|
|
|
2011-05-23 18:07:00 +00:00
|
|
|
#include <boost/endian/detail/disable_warnings.hpp>
|
|
|
|
|
|
|
|
|
|
#include <boost/endian/integers.hpp>
|
2009-03-15 14:41:41 +00:00
|
|
|
#include <boost/binary_stream.hpp>
|
2009-03-12 15:35:35 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using namespace boost;
|
2011-05-23 18:07:00 +00:00
|
|
|
using namespace boost::endian;
|
2009-03-12 15:35:35 +00:00
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2009-03-15 14:41:41 +00:00
|
|
|
int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' }
|
|
|
|
|
// value chosen to work on text stream
|
2009-03-19 14:33:59 +00:00
|
|
|
big32_t b(v);
|
|
|
|
|
little32_t l(v);
|
|
|
|
|
|
2011-05-24 13:21:53 +00:00
|
|
|
std::cout << std::hex << "Hello, endian world!\n\n";
|
2009-03-19 14:33:59 +00:00
|
|
|
|
2011-05-24 13:21:53 +00:00
|
|
|
std::cout << "hex stream output: int_least32_t=" << v
|
|
|
|
|
<< ", big32_t=" << b << ", little32_t=" << l << '\n';
|
|
|
|
|
std::cout << "bin stream output: int_least32_t=" << bin(v)
|
|
|
|
|
<< ", big32_t=" << bin(b) << ", little32_t=" << bin(l) << '\n';
|
2009-03-12 15:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-24 13:21:53 +00:00
|
|
|
// Output on a little endian machine:
|
|
|
|
|
//
|
|
|
|
|
// Hello, endian world!
|
|
|
|
|
//
|
|
|
|
|
// hex stream output: int_least32_t=31323334, big32_t=31323334, little32_t=31323334
|
|
|
|
|
// bin stream output: int_least32_t=4321, big32_t=1234, little32_t=4321
|