Dante May Code
Dante May Code

Reputation: 11247

Why don't we use "unsigned int" instead of "char" to implement a big integer class?

I used to implement something acting as a very large integer using char. But it suddenly occurred to me that I can use unsigned int, which is more straight-forward to implement.

For example, I use every unsigned int to store at most 9 999 999, and make use of the most significant digit as a buffer to increment to the "next" unsigned int.

Thus, I can use 4 byte for 7 digits, instead of 4 digits while using char.

So, why do not we implement a big integer class with unsigned int?

Upvotes: 0

Views: 251

Answers (1)

dlev
dlev

Reputation: 48596

Who says you don't use uint for BigInteger? The C# BCL implementation of BigInteger (in System.Numerics) uses uint[] to store its bits.

In general, it will be more efficient to use the bits to represent a number, rather than the bits to represent the character digit of a number.

Upvotes: 3

Related Questions