C++ 128/256-bit fixed size integer types

前端 未结 4 542
误落风尘
误落风尘 2020-12-03 14:27

I was wondering if any fellow SO\'s could recommend a good light-weight fixed size integer type (128-bit or even 256-bit, possibly even template parametrized) library.

4条回答
  •  暖寄归人
    2020-12-03 15:00

    Depending on your requirements, the STL class bitset might fit your needs. It responds to all the bit-manipulation operators that integer types do (<<,| etc.), but unfortunately not to arithmetic operators like + or *. Its size is fixed at compile time via a template parameter. Another unfortunate thing is that the API provides no way to get at the underlying binary representation (e.g. for streaming it), which might seriously limit its usefulness.

    (I know this is an old question, but this answer might help others.)

提交回复
热议问题