fork download
  1. #include <climits>
  2. #include <cstdint>
  3. #include <cstdio>
  4.  
  5. template <uint8_t d, typename int_type>
  6. int_type get_matches(int_type b)
  7. {
  8. int_type ret = 0;
  9. for (size_t i = 0; i < sizeof(int_type); i++)
  10. if (((b >> i * CHAR_BIT) & 0xff) == d)
  11. ret |= (int_type)0x80 << i * CHAR_BIT;
  12. return ret;
  13. }
  14.  
  15. void print_testcase(uint64_t a)
  16. {
  17. printf("find_matches(0x%016llx) -> 0x%016llx\n", a, get_matches<0x20>(a));
  18. }
  19.  
  20. int main()
  21. {
  22. print_testcase(0x1312202000200212ULL);
  23. print_testcase(0x0001020304050607ULL);
  24. print_testcase(0x0010203040506070ULL);
  25. return 0;
  26. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
find_matches(0x1312202000200212) -> 0x0000808000800000
find_matches(0x0001020304050607) -> 0x0000000000000000
find_matches(0x0010203040506070) -> 0x0000800000000000