How to display hex string as characters in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>

int main(void)
{
    std::string s = "432b2b2050726f6772616d6d696e67";
      
    size_t len = s.length();

    for(size_t i = 0; i < len; i += 2) {
        unsigned int n;   
        std::stringstream ss;
        ss << std::hex << s.substr(i, 2);
        ss >> n;
         
        std::cout << char(n);
    }

    return 0;
}
  
  
  
  
  
/*
run:
  
C++ Programming
 
*/

 



answered Sep 19, 2021 by avibootz

Related questions

1 answer 146 views
1 answer 214 views
2 answers 400 views
400 views asked Dec 29, 2021 by avibootz
1 answer 204 views
2 answers 152 views
152 views asked Sep 18, 2021 by avibootz
1 answer 149 views
2 answers 170 views
170 views asked Dec 29, 2021 by avibootz
...