mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-01-19 16:32:12 +00:00
* Update Jamfile.v2 * Update introduction.qbk * Update tutorial.qbk * Update tutorial_cpp_int.qbk * Update tutorial_gmp_int.qbk * Update tutorial_tommath.qbk * Update integer_examples.cpp * Update tutorial_cpp_bin_float.qbk * Update tutorial_cpp_dec_float.qbk * Update tutorial_gmp_float.qbk * Update tutorial_mpfr_float.qbk * Update tutorial_float128.qbk * Update tutorial_float_builtin_ctor.qbk * Update big_seventh.cpp * Update tutorial_float_eg.qbk * Update floating_point_examples.cpp * Update mpfr_precision.cpp * Update gauss_laguerre_quadrature.cpp * Update tutorial_interval_mpfi.qbk * Update tutorial_cpp_complex.qbk * Update tutorial_mpc_complex.qbk * Update tutorial_float128_complex.qbk * Update tutorial_complex_adaptor.qbk * Update tutorial_rational.qbk * Update tutorial_tommath_rational.qbk * Update tutorial_logged_adaptor.qbk * Update tutorial_debug_adaptor.qbk * Update tutorial_visualizers.qbk * Update tutorial_fwd.qbk * Update tutorial_conversions.qbk * Update tutorial_random.qbk * Update random_snips.cpp * Update tutorial_constexpr.qbk * Update tutorial_import_export.qbk * Update cpp_int_import_export.cpp * Update tutorial_mixed_precision.qbk * Update tutorial_variable_precision.qbk * Update scoped_precision_example.cpp * Update tutorial_numeric_limits.qbk * Update tutorial_numeric_limits.qbk * Update numeric_limits_snips.cpp * Update numeric_limits_snips.cpp * Update tutorial_numeric_limits.qbk * Update numeric_limits_snips.cpp * Update numeric_limits_snips.cpp * Update tutorial_io.qbk * Update reference_number.qbk * Update reference_cpp_bin_float.qbk * Update reference_cpp_double_fp_backend.qbk * Update reference_internal_support.qbk * Update reference_backend_requirements.qbk * Update performance.qbk * Update performance_overhead.qbk * Update performance_real_world.qbk * Update performance_integer_real_world.qbk * Update performance_rational_real_world.qbk * Update reference_number.qbk * Update tutorial_numeric_limits.qbk * Update reference_backend_requirements.qbk
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
///////////////////////////////////////////////////////////////
|
|
// Copyright 2015 John Maddock. Distributed under the Boost
|
|
// Software License, Version 1.0. (See accompanying file
|
|
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
|
|
|
|
#include <boost/multiprecision/cpp_int.hpp>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <vector>
|
|
#include <iterator>
|
|
|
|
//[IE1
|
|
|
|
/*`
|
|
In this simple example, we'll import/export the bits of a cpp_int
|
|
to a vector of 8-bit unsigned values:
|
|
*/
|
|
/*=
|
|
#include <boost/multiprecision/cpp_int.hpp>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <vector>
|
|
#include <iterator>
|
|
*/
|
|
|
|
int main()
|
|
{
|
|
using boost::multiprecision::cpp_int;
|
|
// Create a cpp_int with just a couple of bits set:
|
|
cpp_int i;
|
|
bit_set(i, 5000); // set the 5000th bit
|
|
bit_set(i, 200);
|
|
bit_set(i, 50);
|
|
// export into 8-bit unsigned values, most significant bit first:
|
|
std::vector<unsigned char> v;
|
|
export_bits(i, std::back_inserter(v), 8);
|
|
// import back again, and check for equality:
|
|
cpp_int j;
|
|
import_bits(j, v.begin(), v.end());
|
|
BOOST_MP_ASSERT(i == j);
|
|
}
|
|
|
|
//]
|