I work with some bitwise operators, and I want to extract the last 16 binary digits of a number and perform an operation with them. I basically want to see the negative int as 0xFFFFFFFF, and then extract the LSB FFFF and concatenate them with 0 so that I end up with zero, so that it looks like 0x0000FFFF . I only care about smaller negative numbers, so LSB should be all the necessary information.
Here is my approach in C:
#include <stdio.h> int main(){ int a = -1, c = 0; short b = (short)a; printf("a is %x\nb is %x",a,b); c = (0 << 16) | b; printf("\nc is %x\n", c); return 0; }
My thought process is that I can convert my int a to short so that it looks like FFFF instead of FFFFFFFF . I will feel better. Unfortunately for me it just prints FFFFFFFF for variables
source share