Q:

In a byte, how to swap the 4 higher bits with its 4 lower bits

I had an interview yesterday.
One of the question i've been asked was:
how can one replace the 4 higher bits of a byte with its 4 lower bits.
We're talking on native C here, btw.
For example, consider the following byte:
AB
The output should be:
BA
Well, the guy there told me it can be done within a single command.
I've only managed to do it in 3 commands.
I asked him for the answer, but he was reluctant.
Thanks! 

A:

uint8_t b = 0xab;

b = (b << 4) | (b >> 4);

b now equals 0xba.
Is that what you meant?

A:

I think this might be the answer your interviewer was looking for:
unsigned char a = 0xab;
a *= 16.0625;

It's short and pretty, but it won't be too efficient when compiled.

A:

In gcc on x86, you can use ror as a single inline assembler operation;
unsigned char a = 0x45;

asm("ror $4,%1" : "+r" (a));

printf("0x%x\n", a);

Outputs 0x54.
As an alternative, as suggested by OmriBarel in the comments, if you can do some preparations, a lookup will work also;
uint8_t* lookup = malloc(256);
unsigned int i;
for(i=0; i<256; i++) lookup[i]= i>>4 | i<<4;

uint8_t a = 0x54;
a = lookup[a];
printf("0x%x\n", a);

Outputs 0x45.

