35 using namespace scc::encode;
37 void Hex::bin_to_hex(
const void* xloc,
size_t len, std::string& hex,
bool lower_case)
39 char* loc = (
char*)xloc;
43 char* out = (
char*)hex.data();
45 char hc = lower_case ?
'a' :
'A';
49 char hi = (*loc >> 4) & 0xf;
74 std::string
Hex::bin_to_hexstr(
const void* loc,
size_t len,
const std::string& delimit,
int limit,
const std::string& limit_msg,
bool lower_case)
81 for (
size_t i = 0; i < hex.size(); i += 2)
92 s << hex[i] << hex[i+1];
102 std::string
Hex::bin_to_hexstr(
const std::vector<char>& bin,
const std::string& delimit,
int limit,
const std::string& limit_msg,
bool lower_case)
104 return bin_to_hexstr(bin.data(), bin.size(), delimit, limit, limit_msg, lower_case);
109 bin_to_hex(bin.data(), bin.size(), hex, lower_case);
128 bin.resize(hex.size()/2);
131 for (
size_t i = 0; i < hex.size()-1; i += 2)
136 if (hi >=
'0' && hi <=
'9')
140 else if (hi >=
'a' && hi <=
'f')
144 else if (hi >=
'A' && hi <=
'F')
153 if (lo >=
'0' && lo <=
'9')
157 else if (lo >=
'a' && lo <=
'f')
161 else if (lo >=
'A' && lo <=
'F')
170 bin[i/2] = ((hi << 4) | lo);
static void bin_to_hex(const std::vector< char > &, std::string &, bool=true)
Encode to hex from binary.
static std::string bin_to_hexstr(const std::vector< char > &, const std::string &="", int limit=-1, const std::string &=" +more", bool=true)
Binary to human readable string.
static void hex_to_bin(const std::string &, std::vector< char > &)
Decode from hex to binary.
Binary to hex string converter.