Search code examples
c++boostbiginteger

How to declare manually uint512_t in boost?


i wanna declare this:

uint512_t qwe = 0x5FBFF498AA938CE739B8E022FBAFEF40563F6E6A3472FC2A514C0CE9DAE23B7E;

but c++ don't think so(vscode hints too):

integer constant is too large for its type

and its print like:

x: 0x514c0ce9dae23b7e

can you help me please?


Solution

  • You can use user-defined literals to initialize Boost.Multiprecision numbers, for example:

    uint512_t qwe =
         0x5FBFF498AA938CE739B8E022FBAFEF40563F6E6A3472FC2A514C0CE9DAE23B7E_cppui512;
    

    Alternatively, you could use a constructor from string, but this is less efficient as it will require run time parsing. It can be useful if the number is not a compile-time constant.