Do you want to reverse the bits (binary digits) or do you want to reverse the hex digits? You contradict yourself.
0xABCD is binary 1010101111001101, so reversing the bits would be 1011001111010101, which is 0xB3D5.
In general, to reverse digits (in any base) you need to extract the digits, reverse them, and then repack them. Computers use binary internally, so reversing digits in any power-of-2 base is relatively easy -- you just shift and mask them to extract and shift and bitwise-or them to recombine.
unsigned reverse16binary(unsigned val) {
/* reverse bits in a 16-bit binary number */
unsigned rv = 0;
for (int bit = 0; bit < 16; bit++) {
int digit = (val >> bit) & 1; // extract a digit
rv |= digit << (15 - bit); // stick it in the result
}
return rv;
}
unsigned reverse16hex(unsigned val) {
/* reverse hex digits in a 16-bit binary number */
unsigned rv = 0;
for (int bit = 0; bit < 16; bit += 4) {
int digit = (val >> bit) & 0xf; // extract a digit
rv |= digit << (12 - bit); // stick it in the result
}
return rv;
}
unsigned reverse_general(unsigned val, int bits, int base) {
/* reverse base 2**"base" digits in a "bits"-bit binary number
bits must be <= sizeof(unsigned) * CHAR_BIT and a multiple of base
base must be < sizeof(unsigned) * CHAR_BIT */
unsigned rv = 0;
for (int bit = 0; bit < bits; bit += base) {
int digit = (val >> bit) & ((1 << base) - 1); // extract a digit
rv |= digit << (bits - base - bit); // stick it in the result
}
return rv;
}