E
E
Egorithm2017-01-06 21:35:10
C++ / C#
Egorithm, 2017-01-06 21:35:10

How to use stdint.h?

In general, I had a problem, I didn’t know how to save very large numbers (they needed them for encryption).
And so I found the stdint.h library by chance . The following types are defined there:
207c7589645543c8a46e69698b253c1a.png
The largest uint_fast64_t = 2^64-1
2^64
93d68f93a080474b93c3db43729b9a97.png
I tried to do something with it:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main(void)
{
  uint_fast64_t number = 18446744073709551615;

  printf("%d\n",number);

  system("pause");
  return 0;
}

And this is what I got:
C:\Users\Егор\Desktop>gcc -std=c11 verybigint.c
verybigint.c: In function 'main':
verybigint.c:7:25: warning: integer constant is too large for its type
  uint_fast64_t number = 18446744073709551615;
                         ^

He doesn’t even want to be assigned, how to deduce this is also not clear.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
1
15432, 2017-01-06
@EgoRusMarch

For crypto, if you want to touch the handles - either BigDigits, everything you need is there (simplicity check, exponentiation, working with very large numbers, etc.)
www.di-mgt.com.au/bigdigits.html
according to your question - your number is incorrect
184467440737095511615
18446744073709551615 <-- correct
(I'm flattered, or has the number changed to the correct one in the question?)
and you can use the type unsigned long long
unsigned long long number = 18446744073709551615; //I compile flawlessly
IMHO, it's easier in hexadecimal:
unsigned long long number = 0xFFFFFFFFFFFFFF;

J
jcmvbkbc, 2017-01-06
@jcmvbkbc

uint_fast64_t number = 184467440737095511615;

In this place you need to write
uint_fast64_t number = UINT64_C(184467440737095511615);
Inttypes.h has macros for formatting types from stdint.h to printf, you need PRIuFAST64:
Well, yes, these types will most likely not be enough for cryptography. I will advertise https://gmplib.org/ for a change.

R
Rsa97, 2017-01-06
@Rsa97

You have an extra one in your constant
1844674407370955 1 1615

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question