Exemplo n.º 1
0
/* Convert a string of characters representing a hex buffer into a series of bytes of that real value */
uint8_t *hexStringToBytes(char *inhex)
{
    uint8_t *retval;
    uint8_t *p;
    int len, i;
    
    len = strlen(inhex) / 2;
    retval = malloc(len+1);
    for(i=0, p = (uint8_t *) inhex; i<len; i++) {
        retval[i] = (nibbleFromChar(*p) << 4) | nibbleFromChar(*(p+1));
        p += 2;
    }
    retval[len] = 0;
    return retval;
}
Exemplo n.º 2
0
/* Convert a string of characters representing a hex buffer into a series of bytes of that real value */
byteBuffer
hexStringToBytes(char *inhex)
{
	byteBuffer retval;
	uint8_t *p;
	int len, i;
	
	len = (int) strlen(inhex) / 2;
	if((retval = mallocByteBuffer(len)) == NULL) return NULL;
    
	for(i=0, p = (uint8_t *) inhex; i<len; i++) {
        retval->bytes[i] = (nibbleFromChar(*p) << 4) | nibbleFromChar(*(p+1));
        p += 2;
	}
    retval->bytes[len] = 0;
	return retval;
}