If I impement BigInteger
with a character array (in C++), in terms of power of 10, what is my upper bound in a 32bit system?
In other words,
- 10^x < N <= 10^x
(first character is reserved for sign).
What is x
in 32 bit system?
Please ignore for now that we have reserved memory for OS and consider all 4GB memory is addressable by us.
An 8-bit byte can hold 2 8 , or 256 unique values.
4GB of memory is 2 32 , or 4294967296 bytes .
Or 4294967295, if we subtract the one byte that you want to reserve for a sign
That's 34359738360 bits .
This many bits can hold 2 34359738360 unique values.
- 10^x < N <= 10^x
(first character is reserved for sign).
What is x in 32 bit system?
Wolfram Alpha suggests - 10^1292913986 < N <= 10^1292913986
as the largest representable powers of 10.
So x is 1,292,913,986.
(−(2^(n−1))) to (2^(n−1) − 1)
calculates the range of a signed integer where n
is the number of bits. [1]
Assuming your referring to the whole 4GB of memory being allocated, that is 2 32 (4,294,967,295) addressable bytes in 32 bit memory space, which is 2 35 (34,359,738,368) bits.
Put that into the formula at the start and you get a range of - (2 2 35 -1 ) to 2 2 35 -1 -1
This is assuming you use a bit for a sign, instead of a whole byte. If your going a use a whole byte for sign, you should calculate the unsigned range of 2 35 -8 bits. Which is from 0 to 2 2 35 -8 −1
According to this page, to convert from an exponent of base 2 to an exponent of base 10, you should use the formula x = m*ln(2)/ln(10),where you are converting from 2 m to 10 x .
Therefore, your answer is that the upper bound is 10 2 35 -8 *ln(2)/ln(10) . I'm not going to even attempt to change that exponent into a decimal value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.