alessio211734 said:
Using c language what's the best way to display a byte array as char *
An example byte array 10 255 10 I want display as char* "0A FF 0A" in
hex.
Since I'm reading this in clc++, I'll assume you meant C++, not C. Well,
here's one way, ought to be good enough.
#include <algorithm>
#include <iostream>
#include <ostream>
typedef unsigned char byte;template<typename t>struct d:std
::unary_function<t, void>{void operator() (t const&x){std::
cout<<x;}};template<typename t>struct h:std::unary_function
<t,byte>{byte operator() (t const&x){int f=55+(x&15);return
f<65?f-7:f;}};template<class t,typename f,typename g>struct
hd :std::unary_function<t, void>{void operator()(t const&x)
{f h;g d;h(d(x>>4));h(d(x));h(' ');}};
int main(){
byte a[]={1,8,10,15,16,29,31,32,127,128,200,255,10};
std::for_each(a,a+sizeof(a),hd<byte,d<byte>,h<byte> >());
std::cout<<std::endl;return 0;}