473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C-Question

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 1385
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
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 <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>

Apr 24 '06 #3
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PinkBishop | last post by:
Hello All, Hope you can help. Below is the code I use to send data from form to database. Problem is if an apostrophe is entered in cQuestion field or any field for that matter the form...
7
by: The Doctor | last post by:
A rather elementary question, In VB5, how can I pass a variable from one form to another?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.