-2

How can I create 80 bit unsigned variable? After creating, I need to do some shifting operation so in my case; is unsigned long long key=0x00000000000000000000 valid?

There is const unsigned __int64; can I change it with unsigned __int80?

GingerPlusPlus
  • 5,336
  • 1
  • 29
  • 52
  • 2
    http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Hans Passant Jan 16 '16 at 12:11
  • Possible duplicate of [C++ What variable type for extremely big integer numbers?](http://stackoverflow.com/questions/15400031/c-what-variable-type-for-extremely-big-integer-numbers) – GingerPlusPlus Jan 16 '16 at 12:17
  • 3
    80 bits can be made up of 64+16 bits, or 5*16 bits, or possibly `__int128` on some systems. Which one is better depends on what you are going to do with it (which you forgot to tell us). – Bo Persson Jan 16 '16 at 12:17
  • 2
    [Is there a 128 bit integer in C++?](http://stackoverflow.com/questions/18439520/is-there-a-128-bit-integer-in-c), [Representing 128-bit numbers in C++](http://stackoverflow.com/q/1188939/3821804), [Is there a 128 bit integer in gcc?](http://stackoverflow.com/q/16088282/3821804) – GingerPlusPlus Jan 16 '16 at 12:31
  • 2
    What language are you actually using? The answers may differ between C and C++. – Alan Stokes Jan 16 '16 at 13:22

1 Answers1

4

Your fundamental data types are limited by the architecture of your computer, so probably 8-bit, 16-bit, and 32-bit integers, and possibly 64-bit integers.

Some machines have clever extensions for 128-bit integers, but on others you have to compose types to achieve that, which is done for you in the background by so-called "bigint" libraries. They might, for example, wrap two 64-bit integers into a "128-bit integer" class that transparently handles the carry-over when incrementing/decrementing the resulting value.

There's no particular reason I can think of that you can't apply the same logic to a "bigint" class that wraps a 64-bit integer and a 16-bit integer, or five 16-bit integers — which is best for you depends on your use case, so you could try both and measure.

I like Boost.LargeInt1, with which you could write typedef large_int<uint64_t, uint16_t> uint80_t; then just get on with writing your program.

As it happens, this library already has examples of precisely this, for 96-bit, 160-bit and 192-bit integers.

Alternatively, purchase an 80-bit computer.

1 Confusingly so-named because it was submitted for inclusion in Boost, not because it's actually a Boost library.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055