什么是用C任意重新present大数字的最佳方式? [英] What is the best way to represent arbitrarily big numbers in c?

查看:140
本文介绍了什么是用C任意重新present大数字的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,需要我比C中的最大数值数据类型更大的数字工作的项目。我想使用结构与位域重新present这一点,但它已经有难闻的气味。任何人有什么秘诀吗? (不找一个图书馆,更多的是思维过程去后面做这样的事情的。)

I'm working on a project that requires me to work with numbers larger than the largest numerical datatype in c. I was thinking of using structs with bit fields to represent this, but it's already smelling bad. Anyone got any tips? (Not looking for a library, more of a thought process to go behind doing something like this.)

推荐答案

我建议首先检查了GNU MP Bignum的库。

I suggest to first check out the GNU MP Bignum library.

如果授权是你必须推出自己的一个问题。我对数据类型的第一选择将是无符号的字符的简单数组有一些额外的数据来表示数组有多大一起。

If licensing is a problem you have to roll your own. My first choice for the data-type would be a simple array of unsigned chars along with some extra data to denote how large that array is.

事情是这样的:

typedef struct 
{
  unsigned char * NumberData;
  size_t          AllocatedSize;
} MyBigNum;

应该是足够的。

这篇关于什么是用C任意重新present大数字的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆