Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying 64-bit unsigned integer literals on 64-bit data models

As there are various types of 64-bit data models (LLP64/IL32P64, LP64/I32LP64, ILP64, SILP64), what is the standard conforming way of specifying 64-bit unsigned integer literals?

Would specifying the suffix of ULL be sufficient? Or would I end up causing the literal to be interpreted as 128-bit on some data models?

like image 605
Zach Saw Avatar asked Oct 31 '12 12:10

Zach Saw


People also ask

What is an unsigned 64-bit integer?

uint64. A 64-bit unsigned integer. It has a minimum value of 0 and a maximum value of (2^64)-1 (inclusive).

How do you declare a 64-bit integer in C ++?

Microsoft C/C++ features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intN type specifier, where N is 8, 16, 32, or 64.

How many integers can be represented in 64 bits?

As a recap, remember that the maximum number stored in a 64 bit register / variable is 2^64 – 1 = 18446744073709551615 (a 20 digit number).

How many values can 64 bits store?

A 64-bit register can hold any of 264 (over 18 quintillion or 1.8×1019) different values. The range of integer values that can be stored in 64 bits depends on the integer representation used.


1 Answers

You should use <cstdint> / <stdint.h>, if you have it. This will give you:

  • uint64_t is an unsigned integer type which is 64 bits in size
  • UINT64_C() is a macro for creating constants of the type uint64_t, by having the macro append the proper suffix.
like image 197
unwind Avatar answered Sep 21 '22 14:09

unwind