fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdint>
  4.  
  5. void to_binary(const char *const p, std::size_t bytes)
  6. {
  7. for (std::size_t byte = 0; byte < bytes; ++byte)
  8. {
  9. std::cout << "byte" << byte << ": " ;
  10.  
  11. for (std::uint8_t bit = 1; bit; bit <<= 1)
  12. {
  13. std::cout << ((p[byte] & bit) ? 1 : 0);
  14. }
  15.  
  16. std::cout << '\n';
  17. }
  18. }
  19.  
  20. int main(int argc, char **argv)
  21. {
  22. to_binary(*argv, std::strlen(*argv));
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
byte0: 01110100
byte1: 11110100
byte2: 00001110
byte3: 01001110
byte4: 11110110
byte5: 11100110