return string (b ? "true" : "false");
}
+string
+String_convert::bin2hex (Byte bin_char)
+{
+ string str;
+ str += to_string ((char) nibble2hex_byte ((Byte)(bin_char >> 4)));
+ str += to_string ((char) nibble2hex_byte (bin_char++));
+ return str;
+}
+
string
String_convert::bin2hex (string bin_string)
{
Byte const *byte = (Byte const*)bin_string.data ();
for (ssize i = 0; i < bin_string.length (); i++)
{
- str += to_string ((char)nibble2hex_byte (*byte >> 4));
+ str += to_string ((char)nibble2hex_byte ((Byte)(*byte >> 4)));
str += to_string ((char)nibble2hex_byte (*byte++));
}
return str;
return result_u;
}
-// breendet imp from string
int
String_convert::dec2int (string dec_string)
{
return 0;
long l = 0;
- int conv = sscanf (dec_string.c_str (), "%ld", &l);
- assert (conv);
+ if (!sscanf (dec_string.c_str (), "%ld", &l))
+ assert (false);
+ assert (form_string ("%ld", l) == dec_string);
+
return (int)l;
}
{
if (!dec_string.length ())
return 0;
- double d = 0;
- int conv = sscanf (dec_string.c_str (), "%lf", &d);
- assert (conv);
+
+ double d = 0.0;
+ if (!sscanf (dec_string.c_str (), "%lf", &d))
+ assert (false);
+
return d;
}
int high_i = hex2nibble (*byte++);
int low_i = hex2nibble (*byte++);
if (high_i < 0 || low_i < 0)
- return 1; // illegal char
+ return 1; // invalid char
bin_string_r += to_string ((char) (high_i << 4 | low_i), 1);
i += 2;
}
String_convert::hex2bin (string hex_string)
{
string str;
- // silly, asserts should alway be "on"!
- // assert (!hex2bin (hex_string, str) );
- int error_i = hex2bin (hex_string, str);
- assert (!error_i);
+
+ if (hex2bin (hex_string, str))
+ assert (false);
+
return str;
}
String_convert::nibble2hex_byte (Byte byte)
{
if ((byte & 0x0f) <= 9)
- return (byte & 0x0f) + '0';
+ return (Byte)((byte & 0x0f) + '0');
else
- return (byte & 0x0f) - 10 + 'a';
+ return (Byte)((byte & 0x0f) - 10 + 'a');
}
/**
Convert an integer to a string