Skip to content

Instantly share code, notes, and snippets.

@ciffelia
Created September 28, 2018 11:48
Show Gist options
  • Save ciffelia/2b6537f45f4d3e20cf774f4e708f4f93 to your computer and use it in GitHub Desktop.
Save ciffelia/2b6537f45f4d3e20cf774f4e708f4f93 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <bitset>
#include <unordered_set>
#include <climits>
constexpr auto uint64_bits = CHAR_BIT * sizeof(uint64_t);
using show_bits = std::bitset<uint64_bits>;
uint64_t to_bitmask(const std::unordered_set<uint8_t>& from)
{
uint64_t bits = 0;
for (const auto i : from)
{
bits |= (uint64_t(1) << i);
}
return bits;
}
int main()
{
std::cout << show_bits(to_bitmask({ 0, 2, 3, 32 })) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment