Now let's see what happens. Let's start with the given code:
struct A { int a:3; }; int main() { struct A p = {5}; printf("%d",pa); }
within 3 bits, the values will be 101 (5), since the sign bit of this 3-bit set is 1, thus a negative value. So we need to find 2 compliments of 101, which will be 011 (3). Thus, applying the logic above, we will output as -3. Similarly, others can be proved.
eg. for 1001 (9) we will take 3 bit values due to: 3. so it will be 001 (1). Since here the sign bit is not set, that is 1, so you do not need to use 2 additions. The direct answer will be 1. In the same way, others could be done.
suraj.prasoon
source share