# very very very long integer

Discussion in 'C Programming' started by Abhishek Jha, Oct 16, 2004.

1. ### Abhishek JhaGuest

You can implement very very long integer using strings. Strings have
no limit and using your own code implementation you can store the
numbers of as much length as you want..........for more details
contact at

Abhishek Jha, Oct 16, 2004

2. ### Karthik KumarGuest

Abhishek Jha wrote:
> You can implement very very long integer using strings. Strings have
> no limit and using your own code implementation you can store the
> numbers of as much length as you want..........for more details
> contact at

But how would u perform the arithmetic operations
if you are storing them as strings.

--
Karthik. http://akktech.blogspot.com .
' Remove _nospamplz from my email to mail me. '

Karthik Kumar, Oct 16, 2004

3. ### jacob naviaGuest

Karthik Kumar wrote:
> Abhishek Jha wrote:
>
>> You can implement very very long integer using strings. Strings have
>> no limit and using your own code implementation you can store the
>> numbers of as much length as you want..........for more details
>> contact at

>
>
> But how would u perform the arithmetic operations
> if you are storing them as strings.
>

You can do that without any problems:
"12345"
+
"12345"

Start at the end:
Carry = 0

loop:
('5' - '0') + ('5' - '0') ==> result 10

write Carry + '0' + result%10 to output string.

Carry = result/10,

goto loop;

Some bignums libraries use this representation.

jacob navia, Oct 16, 2004
4. ### Karthik KumarGuest

jacob navia wrote:
> Karthik Kumar wrote:
>
>> Abhishek Jha wrote:
>>
>>> You can implement very very long integer using strings. Strings have
>>> no limit and using your own code implementation you can store the
>>> numbers of as much length as you want..........for more details
>>> contact at

>>
>>
>>
>> But how would u perform the arithmetic operations
>> if you are storing them as strings.
>>

> You can do that without any problems:
> "12345"
> +
> "12345"
>
> Start at the end:
> Carry = 0
>
> loop:
> ('5' - '0') + ('5' - '0') ==> result 10
>
> write Carry + '0' + result%10 to output string.
>
> Carry = result/10,
>
> goto loop;
>
> Some bignums libraries use this representation.
>
>

Apparently that seems less efficient in terms of computation
complexity compared to a linked list. The reason is here -
at any given time, we are processing one digit. Whereas when represented
as long, we can process a good number of digits at any given time , more
than 1.

--
Karthik. http://akktech.blogspot.com .
' Remove _nospamplz from my email to mail me. '

Karthik Kumar, Oct 17, 2004
5. ### jacob naviaGuest

Karthik Kumar wrote:
> jacob navia wrote:
>
>> Karthik Kumar wrote:
>>

> Apparently that seems less efficient in terms of computation
> complexity compared to a linked list. The reason is here -
> at any given time, we are processing one digit. Whereas when represented
> as long, we can process a good number of digits at any given time , more
> than 1.
>

Yes. But it is easier to handle than binary, and binary-->decimals
conversions are very cheap... nothing needs to be done.

jacob navia, Oct 17, 2004