- May 23, 2004
- 218
- 1
- 0
Originally posted by: sao123
2 ^ 1048576
too large for any 32bit computer to compute.
Originally posted by: sao123
I realized my mistake as soon as i walked away from my computer...and went to lunch...
would not the correct value be
2 ^ (8 * 1024 * 1024) or
2 ^ 8388608
It's 2^(1024^2) * (2^8 = 256)2 ^ (256 * 1024 * 1024), not (8 * 1024 * 1024).
Yes.do you just want it in decimal?
Originally posted by: Nail
It's 2^(1024^2) * (2^8 = 256)2 ^ (256 * 1024 * 1024), not (8 * 1024 * 1024).
Yes.do you just want it in decimal?
Originally posted by: Nail
So I'll slam all of this into an array and add in sections. Is there an easier way?
Actually, I have a 64-bit machine, yet I don't know how to use the 64-bit functions (oy!). I doubt it would help much either way.
Originally posted by: sao123
I am performing the calculation...using an array based multiplier.
The array im using has (1024 * 1024 * 4) digits in it. I'm hoping that
a) I wont run out of memory.
b) That will have enough didgits for the calculation.
I suspect it will take about 4-6 hours to complete this task.
Originally posted by: sao123
What i want to know is.... if you put this entire number in a notepad (.txt) file, what is the size of that file?
Originally posted by: Matthias99
Originally posted by: Nail
It's 2^(1024^2) * (2^8 = 256)2 ^ (256 * 1024 * 1024), not (8 * 1024 * 1024).
Ah, you're right. I put the 2^8 in the exponent instead of 2^3. Grrrr. I did know the first one was wrong, though.
8 (2^3) bits per byte, 256 (2^8) permutations per byte. So it's 2^(2^3 * 2^20), or 2^(2^23) = 2^(8,388,608), as given above. However, it's not 2^(2^20) * 2^8, which would be 2^(2^20 + 8), which is not 2^(2^23).
Yes.do you just want it in decimal?
Well, you can do this:
x = 2^(2^23)
log2(x) = 2^23
And then convert from log2 to log10 (I'm blanking on what you do here), and then get it in the form x = 10^(a) (that is, scientific notation). That would be pretty close. Trying to calculate it out on a computer would be a PITA, as the number of bits required to represent this number is on the order of several megabytes (at least 2^23 bits!)
Originally posted by: Matthias99
Originally posted by: sao123
What i want to know is.... if you put this entire number in a notepad (.txt) file, what is the size of that file?
Depends on the encoding. If you take the ASCII representation of it (as f95toli suggests), it will be 2525223 bytes. If it's stored in a binary encoding, an n-bit number requires log2(n) bits to store.
Originally posted by: TuxDave
Originally posted by: Matthias99
Originally posted by: sao123
What i want to know is.... if you put this entire number in a notepad (.txt) file, what is the size of that file?
Depends on the encoding. If you take the ASCII representation of it (as f95toli suggests), it will be 2525223 bytes. If it's stored in a binary encoding, an n-bit number requires log2(n) bits to store.
But the binary encoding method would be very compressable since it would just be a 1 with a whole bunch of zeros after it.
#include <iostream>
#include <string>
using namespace std;
//assumes "digits" in string are ascii \0 through ascii 9 (cntrl-i) rather than the characters '0'-'9'
//for speed purposes
void doubleStringValue(string& s)
{
long len = s.length();
int carry = 0;
for(long pos=len-1;pos>=0;pos--)
{
char *c=&(s[pos]);
int digval = (*c << 1) | carry;
carry = (digval>9);
*c = (carry)?digval-10:Digval;
}
if(carry) s=string("\01")+s;
}
int main(int argc, char *argv[])
{
if(argc<2)
{
cout << "Usage: " << argv[0] << " <n>\n";
return 0;
}
int n = atoi(argv[1]);
string result="\01";
for(int x=0;x<n;x++)
{
doubleStringValue(result);
}
int len=result.length();
for(x=0;x<len;x++)
{
result[x] = '0'+result[x];
}
cout << result << "\n";
return 0;
}