hi,
int i=1;
printf("%x",-1<<1);
what is an output? how is it works? please any one explain it.
I don't know why you included int i = 1; you are not using i in this code.
%x represent hex means your output will be in hexadecimal notation.
The << operator shifts its first operand left by a number of bits given by its second operand
-1 << 1 will make 11111111 into 11111110 which represent -2
-1 is represented in Hex as FFFF your output -2 in hex will be FFFE
thanks
I not understood this concept i is not printed no out put on the screen i is never used for the program
I not understood this concept i is not printed no out put on the screen i is never used for the program
if u use turboc or bc u will get the 0 is an output. if u execute in gcc. you will get -2 as an output.
operation is convert the 1 as binary format ie 00000001. but value is -1 so use one's complement ie 11111110. then use the left shift operator at once. so will become 11111100. so this is ouput binary format. if u printed as integer means again convert one's complement so will become -2. if u printed as hexa decimal format fffffe.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.