C++ 128/256 位固定大小整数类型

C++ 128/256-bit fixed size integer types(C++ 128/256 位固定大小整数类型)

本文介绍了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).

推荐答案

Boost 库将数据类型作为 multiprecision 库,适用于 128 到 1024 位的类型.

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 位固定大小整数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:C++ 128/256 位固定大小整数类型

基础教程推荐