本文介绍了C ++ 128/256位固定大小的整数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有其他SO可以推荐一个良好的轻量级固定大小的整数类型(128位甚至256位,甚至模板参数化)。

I was wondering if any fellow SO's could recommend a good light-weight fixed size integer type (128-bit or even 256-bit, possibly even template parametrized) library.

我已经看过GMP和co,他们非常关心,但是对于我的目的来说有点太大了,我对这一点上的简单头解决方案感兴趣。性能很重要,目标架构将是x86和x86-64,也是一个合理的许可证(也没有GPL或LGPL)。

I've had a look at GMP and co, they care great, yet are a bit too large for my purposes, I'm interested in simple header only solutions at this point. Performance is important and the target architecture will be x86 and x86-64, also a reasonable license (aka nothing GPL or LGPL).

推荐答案

p> Boost 库的数据类型是库,适用于128到1024位的类型。 p>

The Boost library has data types as part of multiprecision library, for types ranging from 128 to 1024 bits.

#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

int128_t mySignedInt128 = -1;
uint128_t myUnsignedInt128 = 2;
int256_t mySignedInt256 = -3;
uint256_t myUnsignedInt256 = 4;
int512_t mySignedInt512 = -5;
uint512_t myUnsignedInt512 = 6;
int1024_t mySignedInt1024 = -7;
uint1024_t myUnsignedInt1024 = 8;

这篇关于C ++ 128/256位固定大小的整数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:20