424,956 Members | 1,722 Online
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

C-Question

 P: n/a suppose if you have a 32 bit machine and your compiler supports upto 32 bit. How can you store a number like 78919237816924523565634563346124978162347811234123 4166 x 4 into one variable. but this big number you can't store in any varible. because our compiler supports upto 32 bit only. can any body plz answer to this question. Regards Remo Apr 24 '06 #1
3 Replies

 P: 26 I think u can store number starting from 0 to 4294967295 in a unsigned integer variable.( 0 to 2 ^32 -1). Apr 24 '06 #2

 P: n/a Remo opined: suppose if you have a 32 bit machine and your compiler supports upto 32 bit. How can you store a number like 78919237816924523565634563346124978162347811234123 4166 x 4 into one variable. but this big number you can't store in any varible. because our compiler supports upto 32 bit only. Use an array of integers instead. Make it as long as the biggest number you'll need, or allocate it dynamically. One way could be: #define BIG_NUM_SIZE 42 unsigned char big_num[BIG_NUM_SIZE]; Each array element can now hold up to CHAR_BIT number of bits (the number of bits in a byte for your implementation; see ) of your big number. It is, of course, up to you to provide means of doing stuff to such numbers (arithmetic, etc). Depending on your needs, you may use a different type. -- "Besides, I think [Slackware] sounds better than 'Microsoft,' don't you?" (By Patrick Volkerding) Apr 24 '06 #3

 P: n/a Remo wrote: suppose if you have a 32 bit machine and your compiler supports upto 32 bit. How can you store a number like 78919237816924523565634563346124978162347811234123 4166 x 4 into one variable. but this big number you can't store in any varible. because our compiler supports upto 32 bit only. can any body plz answer to this question. log_2(78919237816924523565634563346124978162347811 2341234166*4) = 181.04, therefore the result requires 182 bits to store. If you are willing to sacrifice the least significant digits you can use the floating point representation. Otherwise, you might benefit from using an arbitrary precision library, like OpenSSL's bn. Most Linux and *BSD systems come with this library preinstalled; type "man 3 bn" for documentation. -- Diomidis Spinellis Code Quality: The Open Source Perspective (Addison-Wesley 2006) http://www.spinellis.gr/codequality?clc Apr 24 '06 #4