How to display char array as hex values in C++

1 Answer

0 votes
#include <iostream>

int main() {
    char array[] = {'a', 'b', 'c', 'd', 'e', 'x', 'y'};
    int len = sizeof(array)/sizeof(array[0]);
    
    for (int i=0; i < len; i++)
        std::cout << std::hex << (int)array[i] << " ";

    return 0;
}



  
/*
run:
  
61 62 63 64 65 78 79 
 
*/

 



answered Sep 20, 2021 by avibootz

Related questions

1 answer 149 views
1 answer 141 views
141 views asked Sep 18, 2021 by avibootz
2 answers 400 views
400 views asked Dec 29, 2021 by avibootz
1 answer 203 views
2 answers 152 views
152 views asked Sep 18, 2021 by avibootz
2 answers 207 views
1 answer 213 views
...