void binary_to_text(vector<char>& bytes, stringstream& ss) { int limit = 10000; ss << std::hex; ss.fill('0'); string s; int c = 0; for( auto x : bytes){ if( c%8 == 0){ if(c%16 == 0){ if(c!=0){ ss << " " << s << '\n'; s = ""; } ss.width(8); ss << c << " " ; ss.width(2); } else{ ss << " "; s += " "; } } ss.width(2); ss.fill('0'); ss << (unsigned)(unsigned char)x << " "; if ( 0x30 <= x && x <= 0x80){ s += (char)x; } else{ s += "."; } ++c; if(--limit == 0){ break; } } int shift = 16 - c%16; if (shift > 0){ shift *= 2; if (shift <=16){ ++shift; } for(;shift > 0; --shift){ ss << " "; } ss << s; } }