C-Question

R

Remo

suppose if you have a 32 bit machine and your compiler supports upto 32
bit. How can you store a number like
789192378169245235656345633461249781623478112341234166 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
 
V

Vladimir S. Oka

Remo opined:
suppose if you have a 32 bit machine and your compiler supports upto
32 bit. How can you store a number like
789192378169245235656345633461249781623478112341234166 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 <limits.h>) 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)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
 
D

Diomidis Spinellis

Remo said:
suppose if you have a 32 bit machine and your compiler supports upto 32
bit. How can you store a number like
789192378169245235656345633461249781623478112341234166 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(789192378169245235656345633461249781623478112341234166*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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,953
Members
47,507
Latest member
codeguru31

Latest Threads

Top