NVIDIA Interview Question
Software Engineer / Developersunsigned char hextbl[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
void printhex(unsigned int v)
{
int i;
int start = 0;
for (i=7;i>0;i--)
{
unsigned int p = (0xF<<(i*4)) & v;
if (p)
{
printf("%c", hextbl[p>>(i*4)]);
start = 1;
}
else
{
if (start) printf("0");
else continue;
}
}
printf("%c", hextbl[p & 0xF]);
}
Algo:-
- NewGuy April 26, 20081. convert number in to hex.
2. take every number of hex convert it into ASCII
3. use putchar to print.