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
. Bu开发者_Python百科t 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
?
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.
精彩评论