The following code is convert byte to hex.
When code is writed like 1, when text[i]'s high nibble byte
=F, it will cause htext[i]=0x00, i.e., null.
Therefore, it will produce wrong result.
The cause is that the compiler first does signed extend against text[i],
if text[i]'s high nibble byte=F, assume it 0xF5, the signed extend will let
it 0xFFFFFFF5, the shift right 4 bits, this will lead to 0XFFFFFFFF;
Therefore, hex[(text[i] >> 4)] will be hex[0xFFFFFFFF], it will produce 0,
or null, or segment fault. andhex[(text[i] & 0x0f)] = hex[0x0F] = 'F'
The correct code is write like 2.
1.
void hex_dump(char *text, char *htext, int len)
{
2.