473,320 Members | 2,052 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,320 software developers and data experts.

Integers larger than 64bit - Arithmetic

Hi.

Is it possible to use the C-library to handle integers arbitrary large?

I know how to do arbitrary arithmetic to add and convert the base of a
number, but is there a way to utilize the c-library to aid this?

For example, printf can print an 64-bit integer to base 10, but can you
convert a 512-bit integer the same fashion somehow?

Thanks!
Nov 14 '05 #1
6 6617

"Martin Johansen" <ma******@is.online.no> wrote in message

Is it possible to use the C-library to handle integers arbitrary large?

You have to write your own code. For example

typedef struct
{
unsigned char *data;
int len;
int base;
} HUGE;

Then a function

char *hugetodecimal(HUGE *x)

You also need functions for the basic arithemtic operations.

There are also several huge integer libraries available on the net, e.g. one
at snippets.org.
Nov 14 '05 #2
lcc-win32 supports bignums in its standard
distribution
http://www.cs.virginia.edu/~lcc-win32
Nov 14 '05 #3
In article <TL*************@news2.e.nsc.no>,
"Martin Johansen" <ma******@is.online.no> wrote:
Hi.

Is it possible to use the C-library to handle integers arbitrary large?

I know how to do arbitrary arithmetic to add and convert the base of a
number, but is there a way to utilize the c-library to aid this?

For example, printf can print an 64-bit integer to base 10, but can you
convert a 512-bit integer the same fashion somehow?


printf cannot do this.

You may find a library which can, or you can quite easily write that
code yourself. If the intention is to convert the number into something
that is readable by a human, then you have to give it some more thought.
Nov 14 '05 #4
Martin Johansen wrote:
Hi.

Is it possible to use the C-library to handle integers arbitrary large?

I know how to do arbitrary arithmetic to add and convert the base of a
number, but is there a way to utilize the c-library to aid this?

For example, printf can print an 64-bit integer to base 10, but can you
convert a 512-bit integer the same fashion somehow?

Thanks!


Try implementing a linked list.

typedef struct node {
long val;
struct node * next;
} LongNum;

This way you can store very long values. And you can define
appropriate functions like add, subtract, print etc on the linked list.

HTH
--
Karthik

------

Human Beings please 'removeme' for my email.
Nov 14 '05 #5
"Martin Johansen" <ma******@is.online.no> wrote in message
news:TL*************@news2.e.nsc.no...
Is it possible to use the C-library to handle integers arbitrary large?

I know how to do arbitrary arithmetic to add and convert the base of a
number, but is there a way to utilize the c-library to aid this?

For example, printf can print an 64-bit integer to base 10, but can you
convert a 512-bit integer the same fashion somehow?


The standard C library does not, but there are many third-party libraries
(e.g. OpenSSL) that contain a "bignum" implementation.

S

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin

Nov 14 '05 #6
In <TL*************@news2.e.nsc.no> "Martin Johansen" <ma******@is.online.no> writes:
Is it possible to use the C-library to handle integers arbitrary large?
No, the C-library only supports fixed-size integers.
I know how to do arbitrary arithmetic to add and convert the base of a
number, but is there a way to utilize the c-library to aid this?
Nope.
For example, printf can print an 64-bit integer to base 10, but can you
convert a 512-bit integer the same fashion somehow?


Nope, unless your implementation supports something like int512_t, again,
as a fixed-size integer type.

For arbitrarily sized integers you must use external libraries, the
standard C library provides no support for them.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7

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

Similar topics

87
by: j0mbolar | last post by:
I've read in the standard that addresses basically can't be interpreted as integers. If they can, it is implementation defined behavior. However, if they can't be viewed as integers in any sense...
3
by: Joe Van Dyk | last post by:
What bad things could happen if I compare signed and unsigned integers? (is that even valid C?) Thanks, Joe
8
by: dwelch91 | last post by:
I need to detect whether the operating system I am running on (not the Python version) is 64bit or 32bit. One requirement is that I need to include support for non-Intel/AMD architectures. The 2...
13
by: bob | last post by:
If you were designing a class to represent very large integers in C++, what kind of internal representation would be best?
6
by: Alexander Stoyakin | last post by:
Hello, please advise on the following issue. I need to check that difference between two double values is not higher than defined limit. int main() { double limit = 0.3; double val1 = 0.5,...
9
by: Mark Morss | last post by:
I would like to construct a class that includes both the integers and None. I desire that if x and y are elements of this class, and both are integers, then arithmetic operations between them,...
19
by: robin | last post by:
Hi everybody I have a problem which is puzzling me it is the following: Write a C++ program to find the sum of two integers without using any arithmetic, loops, recursions nothing.
5
by: seung | last post by:
Hi, I'm trying to use uint64_t by #including stdint.h in C on 32-bit machine. However, I can't seem to get the right value for shifting, for example: for(i = 0; i < 64; i++) { c = 1 << i;...
39
by: Juha Nieminen | last post by:
I was once taught that if some integral value can never have negative values, it's a good style to use an 'unsigned' type for that: It's informative, self-documenting, and you are not wasting half...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.