Commit 32a0bdd8 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

conversion function added

parent b4350ab5
......@@ -78,6 +78,7 @@ uint32_t crc32(const uint8_t* data, uint32_t num_bytes, uint32_t seed);
uint32_t hexstr_to_uint32(const char* str);
uint32_t uint16_to_str(uint16_t val, char* out_buffer);
uint32_t bytes_to_hexstr(const uint8_t* bytes, uint32_t num_bytes, char* out_buffer, uint32_t buffer_size);
int32_t str_to_int32(const char* str);
void memb_init(memb_t memb);
void* memb_allocate_block(memb_t memb);
......
......@@ -86,4 +86,24 @@ uint32_t bytes_to_hexstr(const uint8_t* bytes, uint32_t num_bytes, char* out_buf
return len;
}
/*---------------------------------------------------------------------------*/
int32_t str_to_int32(const char* str)
{
int32_t val = 0;
uint8_t neg = 0;
/* skip nun-numerical character at the beginning */
while (*str && (*str < '0' || *str > '9') && (*str != '-')) {
str++;
}
if (*str && (*str == '-')) {
neg = 1;
}
while (*str && (*str >= '0' && *str <= '9')) {
val = val * 10 + (*str - '0');
str++;
}
if (neg) {
val = -val;
}
return val;
}
/*---------------------------------------------------------------------------*/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment