I am new to C so I got confused with this code. I wanted to know how one's complement will work for integer variable
Code:
int f = 45;
printf("Value of %d is = %d",f,~f);
now output is coming as
"Value of 45 is = -46"
My question is: this is integer variable and in my compiler int is of 4 bytes i.e. 2^32
so that means it will be represented in machine as
4294967296 . . . . . . . 32 16 8 4 2 1
0 1 0 1 1 0 1
right? or it will be represented till first 8 bits?
If represented till 32 bits then number between '32' bit and '4294967296' will be 0 right because this is 4 bytes integer and this needs to be represented this way right?
What about representation of number, I need some reference point then. I will research on my own, Assume int is of 4 bytes, if I write int a = 3; will it be represented with 8-bits representation 00000011 or with 00000000000000000000000000000011 and if I write int a = 257, will it be represented with 0000000100000001 or with 00000000000000000000000100000001 Please give me some hint or explanation on this?
Then when we're going to calculate ~ 1s complement, we're going to invert the values of bit, thus in this case bits between 32 and 4294967296 will be turned to 1 from 0 ? If so, then it's going to become some big value? How was this -46 calculated here?