Is there a 128 bit integer in C++?

后端 未结 7 619
滥情空心
滥情空心 2020-12-01 11:41

I need to store a 128 bits long UUID in a variable. Is there a 128-bit datatype in C++? I do not need arithmetic operations, I just want to easily store and read the value v

相关标签:
7条回答
  • 2020-12-01 12:27

    Your question has two parts.

    1.128-bit integer. As suggested by @PatrikBeck boost::multiprecision is good way for really big integers.

    2.Variable to store UUID / GUID / CLSID or whatever you call it. In this case boost::multiprecision is not a good idea. You need GUID structure which is designed for that purpose. As cross-platform tag added, you can simply copy that structure to your code and make it like:

    struct GUID
    {
        uint32_t Data1;
        uint16_t Data2;
        uint16_t Data3;
        uint8_t  Data4[8];
    };
    

    This format is defined by Microsoft because of some inner reasons, you can even simplify it to:

    struct GUID
    {
        uint8_t Data[16];
    };
    

    You will get better performance having simple structure rather than object that can handle bunch of different stuff. Anyway you don't need to do math with GUIDS, so you don't need any fancy object.

    0 讨论(0)
提交回复
热议问题