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!
uint8_t b = 0xab;
b = (b << 4) | (b >> 4);
b
now equals 0xba.
Is that what you meant?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With