Search code examples
c++bit-manipulationshortbitset

How can i convert bitset into short in c++?


if i have a bitset<16> bits(*iter) and a my short how i can assign this bist to my short?

short myShort = ??bits??

It's possible to convert a bitset<16> to short?


Solution

  • You really should use an unsigned short, to avoid language quirks on the high bit.

    unsigned short myShort = (unsigned short)bits.to_ulong();