-1

So im fairly new to C but im trying to store a very very very large number. i couldnt tell you the exact number because it depends on the users input. But im trying to find a way to store something in a way that java or python does by using BigInt.

i would like to handle it like a int as well. (like doing mathematic equations with it)

I tried using every single data type in C with no success.

Pls help

edit: this is for a encryption algorithm i wrote in java. if you go to the github link(https://github.com/N0tA1dan/Krypton) you can see how big of numbers im dealing with. now im trying to write the algorithm in C

NotAidan
  • 11
  • 3
  • 2
    [The GNU MP Bignum Library](https://gmplib.org/)? – MikeCAT Jul 09 '21 at 09:58
  • 1
    Wikipedia: [List of arbitrary-precision arithmetic software](https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software). – Ian Abbott Jul 09 '21 at 10:14
  • Maybe this can help, I didn't try it though: https://stackoverflow.com/a/54815033/10213771 – maths soso Jul 09 '21 at 10:22
  • I guess most crypto libraries support bigints. – Ian Abbott Jul 09 '21 at 10:23
  • In C, you are not going to be able to "handle it like a int". There are plenty of bignum libraries ([GMP](https://gmplib.org) is perhaps the best known), but you are not going to be able to type `a + b` for two bignums; you're going to have to settle for things like `mp_add(a, b)`. – Steve Summit Nov 26 '21 at 14:08

2 Answers2

0

in C Programming , the longest value a user can input in 64 bits is with the long type ( 8 bytes ) , and it's ranged from -9223372036854775808 to 9223372036854775807 . hope I helped you ;)

  • Using `unsigned long long`, you can get a bit farther to `18 446 744 073 709 551 615` but probably not long enough for cryptographic algorithms. – chqrlie Jul 10 '21 at 18:17
0

if you want to store a number in one variable the biggest one is long long and you can store to +18,446,744,073,709,551,615 but if you want to go higher you can input number and store it in form of string for example look at this code(it support number up to max_number digit):

,,,

#include<stdio.h>
#include<string.h>
#define max_number 200
int main()
{
    char arr[max_number];
    scanf("%s",&arr);
    int len_digit=strlen(arr);  // calculate number of digits
    /*
    arr[len-1]=first digit
    arr[len-2]=second digit
    .
    .
    .
    .
    arr[0]=last digit
    */
    return 0;
}
    

,,, if you want to work with number you should typecast array from char to integer for that you can subtract arr[i] (i from 0 to len-1) to 48 because Ascii code of '0' is 48 and it sorted to '9' = 57 and then you can do mathematical calculation

remember for every calculation you should build a function that pass 2 arrays and do mathematical calculate index by index