1 // Copyright 2019 Peter Dimov
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5
6 #include <boost/endian/conversion.hpp>
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/config.hpp>
9 #include <boost/cstdint.hpp>
10 #include <cstddef>
11
main()12 int main()
13 {
14 using namespace boost::endian;
15
16 unsigned char v[] = { 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8 };
17
18 // 16
19
20 BOOST_TEST_EQ( load_little_s16( v ), -3343 );
21 BOOST_TEST_EQ( load_little_u16( v ), 0xF2F1 );
22
23 BOOST_TEST_EQ( load_big_s16( v ), -3598 );
24 BOOST_TEST_EQ( load_big_u16( v ), 0xF1F2 );
25
26 // 24
27
28 BOOST_TEST_EQ( load_little_s24( v ), -789775 );
29 BOOST_TEST_EQ( load_little_u24( v ), 0xF3F2F1 );
30
31 BOOST_TEST_EQ( load_big_s24( v ), -920845 );
32 BOOST_TEST_EQ( load_big_u24( v ), 0xF1F2F3 );
33
34 // 32
35
36 BOOST_TEST_EQ( load_little_s32( v ), 0xF4F3F2F1 );
37 BOOST_TEST_EQ( load_little_u32( v ), 0xF4F3F2F1 );
38
39 BOOST_TEST_EQ( load_big_s32( v ), 0xF1F2F3F4 );
40 BOOST_TEST_EQ( load_big_u32( v ), 0xF1F2F3F4 );
41
42 // 40
43
44 BOOST_TEST_EQ( load_little_s40( v ), -43135012111 );
45 BOOST_TEST_EQ( load_little_u40( v ), 0xF5F4F3F2F1 );
46
47 BOOST_TEST_EQ( load_big_s40( v ), -60348435211 );
48 BOOST_TEST_EQ( load_big_u40( v ), 0xF1F2F3F4F5 );
49
50 // 48
51
52 BOOST_TEST_EQ( load_little_s48( v ), -9938739662095 );
53 BOOST_TEST_EQ( load_little_u48( v ), 0xF6F5F4F3F2F1 );
54
55 BOOST_TEST_EQ( load_big_s48( v ), -15449199413770 );
56 BOOST_TEST_EQ( load_big_u48( v ), 0xF1F2F3F4F5F6 );
57
58 // 56
59
60 BOOST_TEST_EQ( load_little_s56( v ), -2261738553347343 );
61 BOOST_TEST_EQ( load_little_u56( v ), 0xF7F6F5F4F3F2F1 );
62
63 BOOST_TEST_EQ( load_big_s56( v ), -3954995049924873 );
64 BOOST_TEST_EQ( load_big_u56( v ), 0xF1F2F3F4F5F6F7 );
65
66 // 64
67
68 BOOST_TEST_EQ( load_little_s64( v ), 0xF8F7F6F5F4F3F2F1 );
69 BOOST_TEST_EQ( load_little_u64( v ), 0xF8F7F6F5F4F3F2F1 );
70
71 BOOST_TEST_EQ( load_big_s64( v ), 0xF1F2F3F4F5F6F7F8 );
72 BOOST_TEST_EQ( load_big_u64( v ), 0xF1F2F3F4F5F6F7F8 );
73
74 return boost::report_errors();
75 }
76