Working with VERY LARGE numbers

  • Thread starter Thread starter Aamir Mahmood
  • Start date Start date
A

Aamir Mahmood

Hi,

I have working on a system in which I have to manipulate *very* big numbers.
Like
32368060745625089670148189374568111100874165870871388541651800834565616109380834613212956588769877

They may be upto 10000 digits long.

These numbers are coming through a device in ascii format, I am creating a
text file and saving these numbers in the file.
Is there a way that I can convert them into binary.
For example if the incoming number is '14005685717805198227'
it should be saved in file as 11000010 01011110 00110000 11110100 01111101
10001010 01101011 10010011 (binary data) (File size: 8 bytes)
instead of ascii '1', '4', '0', '0', '5', '6', '8', '5', '7', '1', '7',
'8', '0', '5', '1', '9', '8', '2', '2', '7' (ascii/text data) (File size: 20
bytes).

I am looking for a hint on how to implement this, of if there are libraries
availeble to acheive this.

Thanks.

-
AM
 
BTW, I used Windows Calculator program to convert 14005685717805198227
(decimal) into binary.
 
Hi,

I have working on a system in which I have to manipulate *very* big numbers.
Like
323680607456250896701481893745681111008741658708713885416518008345656161093­80834613212956588769877

They may be upto 10000 digits long.

These numbers are coming through a device in ascii format, I am creating a
text file and saving these numbers in the file.
Is there a way that I can convert them into binary.
For example if the incoming number is '14005685717805198227'
it should be saved in file as 11000010 01011110 00110000 11110100 01111101
10001010 01101011 10010011 (binary data) (File size: 8 bytes)
instead of ascii '1', '4', '0', '0', '5', '6', '8', '5', '7', '1', '7',
'8', '0', '5', '1', '9', '8', '2', '2', '7' (ascii/text data) (File size:20
bytes).

I am looking for a hint on how to implement this, of if there are libraries
availeble to acheive this.

Thanks.

-
AM

The J# library contains a BigInteger class.
 
Aamir said:
I have working on a system in which I have to manipulate *very* big numbers.
Like
32368060745625089670148189374568111100874165870871388541651800834565616109380834613212956588769877

They may be upto 10000 digits long.
I am looking for a hint on how to implement this, of if there are libraries
availeble to acheive this.

There should be plenty of bigint libraries for C# available.

http://www.codeproject.com/csharp/biginteger.asp shows up
at the top in Google.

Arne
 
Aamir Mahmood said:
Hi,

I have working on a system in which I have to manipulate *very* big
numbers.
Like
32368060745625089670148189374568111100874165870871388541651800834565616109380834613212956588769877

They may be upto 10000 digits long.

These numbers are coming through a device in ascii format, I am creating a
text file and saving these numbers in the file.
Is there a way that I can convert them into binary.
For example if the incoming number is '14005685717805198227'
it should be saved in file as 11000010 01011110 00110000 11110100 01111101
10001010 01101011 10010011 (binary data) (File size: 8 bytes)
instead of ascii '1', '4', '0', '0', '5', '6', '8', '5', '7', '1', '7',
'8', '0', '5', '1', '9', '8', '2', '2', '7' (ascii/text data) (File size:
20 bytes).

I am looking for a hint on how to implement this, of if there are
libraries availeble to acheive this.

This is the way I did it (originally in VB6).
1) Create a byte array of size 1 with just the values 1 in it. (A)
2) Create a byte array for the result (B)
3) Grab the least significant digit of your value. (C)
4) Add a times c to b
5) Multiply a by 10
6) Repeat, grabbing the next digit along.

You'll need to do something to enlarge the byte arrays as you go. To
multiply by 10 you shift left 2 and add that to the result of shifting left
another 2, eg, to multiply A by 10

x = A << 2
y = x << 2
A = x + y

I can send you the vb6 source code if you like.

Michael
 
Maybe its time to consider using Microsoft F# which was just released and is
a CLR functional language for those working with science, geometry and math
applications. Not widely marketed yet but Microsoft also has a Windows
server for science and engineering where many F# applications will be used
to develop applications supporting parellel processing on the quad cores and
beyond.
 
If all you need to so is store them, you can split the string into
substrings, convert each of these to an unsigned integer, and store it. Each
substring represents a power (exponent) of the number stored in it,
according to its place in the original string. To perform math with it would
require a good bit more work, however.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
I've got to ask. Just what kind of application requires such amazingly
large numbers. 1000 decimal digits is awesome! Are you counting the
electrons in the universe, or something?

SteveT
 
Steve Thackery said:
I've got to ask. Just what kind of application requires such amazingly
large numbers. 1000 decimal digits is awesome! Are you counting the
electrons in the universe, or something?

Bill Gate's personal accounting software? ;-)

Michael
 

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

Similar Threads


Back
Top