如何重新present多位基地2 ^ 32? [英] How to represent a number in base 2^32?

查看:165
本文介绍了如何重新present多位基地2 ^ 32?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一些基本的10或基数为16号,我怎么把它变成基地2 ^ 32?

If I have some base 10 or base 16 number, how do I change it into base 2^32?

我想之所以这样做,是实现由BigInt有这里的其他成员.. <一的建议href=\"http://stackoverflow.com/questions/10178055/why-to-use-higher-base-for-implementing-bigint\">Why为实现BigInt有使用基数较高?

The reason I'm trying to do this, is for implementing BigInt as suggested by other members here .. Why to use higher base for implementing BigInt?

这将是相同的整数(基数为10),直到2 ^ 32?之后会发生什么?

Will it be the same as integer(base 10) till 2^32? What will happen after it?

推荐答案

您正在努力寻找形式的东西。

You are trying to find something of the form

a0 + a1 * (2^32) + a2 * (2^32)^2 + a3 * (2^32)^3 + ...

这是的究竟的一个定义基2 32 系统,所以忽略一切告诉你,你的问题没有意义的人!

which is exactly the definition of a base-232 system, so ignore all the people that told you that your question doesn't make sense!

总之,你所描述的被称为基转换。有快速的方法,有简便的方法来解决这个问题。快速的方法是非常复杂的(有<一个href=\"http://www.amazon.co.uk/$p$pcision-Arithmetic-Encyclopedia-Mathematics-Applications/dp/0521761352/ref=sr_1_1?ie=UTF8&qid=1325537407&sr=8-1\">entire书籍章节的专门讨论这个问题),而且我不会试图在这里解决这些问题(尤其是因为我从来没有尝试使用它们)。

Anyway, what you are describing is known as base conversion. There are quick ways and there are easy ways to solve this. The quick ways are very complicated (there are entire chapters of books dedicated to the subject), and I'm not going to attempt to address them here (not least because I've never attempted to use them).

一个简单的方法是先实现你的电话号码的系统,乘,除两种功能。 (即实施 BigInt有加(BigInt有一个,BigInt有B) BigInt有MUL(BigInt有一个,BigInt有B))。一旦你解决了,你会发现一个基地10号可作为pssed前$ P $:

One easy way is to first implement two functions in your number system, multiplication and addition. (i.e. implement BigInt add(BigInt a, BigInt b) and BigInt mul(BigInt a, BigInt b)). Once you've solved that, you will notice that a base-10 number can be expressed as:

b0 + b1 * 10 + b2 * 10^2 + b3 * 10^3 + ...

其也可以写成:

b0 + 10 * (b1 + 10 * (b2 + 10 * (b3 + ...

所以,如果你在输入字符串移到左到右,你可以一次剥离一个基站10​​位,并使用你的添加 MUL 功能累积到您的 BigInt有

BigInt a = 0;
for each digit b {
    a = add(mul(a, 10), b);
}

声明:这个方法的不可以计算效率,但它至少让你开始

Disclaimer: This method is not computationally efficient, but it will at least get you started.

注意:从基本-16转换为简单,因为2 32 是16的整数倍所以基本上转化来到串联位。

Note: Converting from base-16 is much simpler, because 232 is an exact multiple of 16. So the conversion basically comes down to concatenating bits.

这篇关于如何重新present多位基地2 ^ 32?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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