473,672 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

just curious : printing big numbers - how?

Without getting too mathematical : how do you print/handle big numbers?

for ( int i = 1 ; i < 10 ; i ++)
cout << (123456789 << i) << endl;

246913578
493827156
987654312
1975308624
-344350048
-688700096
-1377400192
1540166912
-1214633472

Oct 20 '05 #1
5 6504
<dr******@gmail .com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
Without getting too mathematical : how do you print/handle big numbers?

for ( int i = 1 ; i < 10 ; i ++)
cout << (123456789 << i) << endl;

246913578
493827156
987654312
1975308624
-344350048
-688700096
-1377400192
1540166912
-1214633472


Hello

You can:
1. use 3rd party big numbers libraries (such as MIRACL)
2. use a bigger data type (like int64)
3. write your own functions that manipulate and display these big numbers.

Regards,
Elias
Oct 20 '05 #2
dr******@gmail. com wrote:
Without getting too mathematical : how do you print/handle big numbers?

for ( int i = 1 ; i < 10 ; i ++)
cout << (123456789 << i) << endl;

246913578
493827156
987654312
1975308624
-344350048
-688700096
-1377400192
1540166912
-1214633472


Generally by keeping an array of n digits. It can't be done with
build-ins. Printing it becomes a trivial matter of an O(n) loop over the
array. The funny thing is that this way you can view a (big) number as a
signal or a formal polynomial and the other way around. Therefore
multiplication can be done as polynomial multiplication (convolution),
which can be done by point-wise multiplication in the frequency/fourier
domain. Cute, no? ;)

--
Regards,

Ferdi Smit (M.Sc.)
Email: Fe********@cwi. nl
Room: C0.07 Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands
Oct 20 '05 #3

Ferdi Smit wrote:
dr******@gmail. com wrote:
Without getting too mathematical : how do you print/handle big numbers?

for ( int i = 1 ; i < 10 ; i ++)
cout << (123456789 << i) << endl;

246913578
493827156
987654312
1975308624
-344350048
-688700096
-1377400192
1540166912
-1214633472


<SNIP>... funny thing is that this way you can view a (big) number as a
signal or a formal polynomial and the other way around. Therefore
multiplication can be done as polynomial multiplication (convolution),
which can be done by point-wise multiplication in the frequency/fourier
domain. Cute, no? ;)
Regards, Ferdi Smit (M.Sc.)

</SNIP>

Thanks guys. But you know I thought I was going to be shown some tiny
piece of code : an example of how to do this using oh I don't know logs
and strings. I appreciate the help Ferdi but I'm afraid I haven't the
foggiest idea of what you are writing about.

Surely this can be done without the need for third party libraries. Can
anyone provide a neat, simple, short code example?

Oct 21 '05 #4
Geo

dr******@gmail. com wrote:
Ferdi Smit wrote:
dr******@gmail. com wrote:
Without getting too mathematical : how do you print/handle big numbers?

for ( int i = 1 ; i < 10 ; i ++)
cout << (123456789 << i) << endl;

246913578
493827156
987654312
1975308624
-344350048
-688700096
-1377400192
1540166912
-1214633472


<SNIP>
... funny thing is that this way you can view a (big) number as a
signal or a formal polynomial and the other way around. Therefore
multiplication can be done as polynomial multiplication (convolution),
which can be done by point-wise multiplication in the frequency/fourier
domain. Cute, no? ;)
Regards, Ferdi Smit (M.Sc.)

</SNIP>

Thanks guys. But you know I thought I was going to be shown some tiny
piece of code : an example of how to do this using oh I don't know logs
and strings. I appreciate the help Ferdi but I'm afraid I haven't the
foggiest idea of what you are writing about.

Surely this can be done without the need for third party libraries. Can
anyone provide a neat, simple, short code example?


The problem is that your question is too vague, if I wanted to just
'print' a big number I'd put it in a string

std::cout << "12345678901234 567890";

Oct 21 '05 #5
> The problem is that your question is too vague, if I wanted to just
'print' a big number I'd put it in a string

std::cout << "12345678901234 567890";


Yes point taken. Does this help : see question in code comment below.

#include <math.h>
#include <string>
#include <errno.h>
#include <iostream.h>

int main()
{

printf("Max of unsigned long long....= %llu \n",ULONG_LONG_ MAX);
printf("Max of long long is .........= %lld \n",LONG_LONG_M AX);
printf("Max of long is ..............= %ld \n", LONG_MAX);

printf("Max of unsigned long long....= %llX hex\n",ULONG_LO NG_MAX);
printf("Max of long long is .........= %llX hex\n",LONG_LON G_MAX);
printf("Max of long is ..............= %lX hex\n", LONG_MAX);

printf("size of unsigned long long....= %d bytes
\n",sizeof(ULON G_LONG_MAX));
printf("size of long long is .........= %d bytes
\n",sizeof(LONG _LONG_MAX));
printf("size of long is ..............= %d bytes \n",
sizeof(LONG_MAX ));
//Ambiguous overloaded function call
// commented out does not compile says: can only find unsigned short...
// cout << ULONG_LONG_MAX << endl;
// cout << LONG_LONG_MAX << endl;
cout << LONG_MAX << endl;

// ok how do you output this number, in any manner : a string would do
// this produces FFFFFFFFFFFFFFF E which is 1 less than ULONG_LONG_MAX
printf("Max of unsigned long long....= %llX \n",2*ULONG_LON G_MAX);

/*
output

Max of unsigned long long....= 184467440737095 51615
Max of long long is .........= 922337203685477 5807
Max of long is ..............= 2147483647
Max of unsigned long long....= FFFFFFFFFFFFFFF F hex
Max of long long is .........= 7FFFFFFFFFFFFFF F hex
Max of long is ..............= 7FFFFFFF hex
size of unsigned long long....= 8 bytes
size of long long is .........= 8 bytes
size of long is ..............= 4 bytes
2147483647
Max of unsigned long long....= FFFFFFFFFFFFFFF E

*/
}

Oct 26 '05 #6

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

Similar topics

3
1583
by: Elaine Jackson | last post by:
I'm new to Python, and I've noticed the following: >>> def f(a,b): a+=b >>> def g(a,b): a=a+b >>> p= >>> q= >>> r= >>> s=
10
2162
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
4
1550
by: Lance | last post by:
Hi all, I'm curious as to the technicalities of why a particular method declaring and calling is faster than the other. The C syntax is: \\\\\ BOOL PathMatchSpec( LPCSTR pszFile, LPCSTR pszSpec );
1
1197
by: Andrej Nerat | last post by:
Greetings, I was playing a bit with web services and asked myself if I could use P/Invoke to create AVI file in Web service from some images(bitmaps). I could already use P/Invoke to incorporate OpenGL to web services (to create images), and I am curious if I could do the same with AVI files or streams? Perhaps someone already tried something like that or knows if it can be done.
4
1292
JavaStudent07
by: JavaStudent07 | last post by:
File file=new File("H:/Numbers.java"); String Text=""; int intNumber=1; BufferedReader lineIn=new BufferedReader(new FileReader(file)); try { Text=lineIn.readLine(); }
4
5335
by: xXmeeeeeXx | last post by:
Hi Everyone, I am trying to create a program that arranges numbers in ascending order. I do not understand how to do this. To start, think that I would need to include several if and else if statements coming values. Than I would use the operators ">" and "<" to compare the int values I have already declared. Could someone explain how to do this? Thanks in advance.
34
8165
by: chandu | last post by:
Hello every body , upto now i saw advantages of C# only,i am curious about what are the disadvantages of C#..(because any programming language should have some positives and negatives..) Thanks Chandu
11
1355
by: Liz | last post by:
anyone have any idea why there have been (at least) 82 VS 2008 post-release messages here on the C# board but only 5 on the VB.NET board; are the VB crowd just not interested?? strikes me as a significant difference but I'm not sure what to make of it ....
0
8930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5704
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.