I am trying to inverse a hexadecimal value. The result is wrong, however.
#include <stdio.h>
#include <stdint.h>
#include <netinet/in.h>
int main(void)
{
uint32_t acc = 0xBBD1;
printf("0x%X", htons(~acc)); // prints 0x2E44
}
Let's do the inversion by hand:
0xBBD1 = 1011 1011 1101 0001
~1011 1011 1101 0001 =
0100 0100 0010 1110
0100 0100 0010 1110 = 0x442E
This means, the code should actually print 0x442E
instead of 0x2E44
.
What's wrong with my code?