How to convert ASCII string to binary values C++

1 Answer

0 votes
#include <iostream>
#include <bitset>

int main()
{
    std::string s = "c++"; 
    const char *arr = s.c_str(); 
 
    for (std::size_t i = 0; i < s.size(); ++i) {
        std::cout << std::bitset<8>(s.c_str()[i]) << "\n";
    } 

   return 0;
}



/*
run:

01100011
00101011
00101011

*/

 



answered Aug 2, 2020 by avibootz

Related questions

1 answer 177 views
1 answer 205 views
1 answer 186 views
1 answer 122 views
1 answer 175 views
1 answer 77 views
77 views asked Nov 18, 2024 by avibootz
...