Created
September 28, 2018 11:48
-
-
Save ciffelia/2b6537f45f4d3e20cf774f4e708f4f93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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