How can I improve my thought process in C interviews instead of relying on memorized solutions?
I was asked an endianness question in a recent Embedded C interview.
For example:
uint32_t n = 0x12345678;
I had previously learned the typical byte-swap approach and also i can do it for 16 bit
n = ((n & 0x000000FF) << 24) |
((n & 0x0000FF00) << 8) |
((n & 0x00FF0000) >> 8) |
((n & 0xFF000000) >> 24);
However, the interviewer asked me to convert the endian representation and store the result into a byte array using a pointer to the destination.
During the interview, my mind immediately went to the bit-manipulation code I had memorized, and I failed to do the simple program. How can I improve my thought process?