0 0 votes Ouput #include<Stdio.h> int main() { int a=10; a=a+ ~a; printf(“%d”,a); } PS:i m getting 15 but 15 is nt ans. Programming in C + – Abhisek Tiwari 4 1.3k views answer comment Share Follow Print See all 10 Comments 10 10 Comments reply Deepanshu commented Jan 14, 2019 reply Follow flag -1 ? 0 0 replyShare Kunal Kadian commented Jan 14, 2019 reply Follow flag ~ does bitwise complement. You are getting 15 bcoz you are taking 10 as 1010 and then complementing it to get 5, but an int is representes by 2 bytes in turbo C compiler and 4 bytes in many other compilers i.e. 32 bits Now try. 1 1 replyShare prashant jha 1 commented Jan 14, 2019 reply Follow flag 01010=10 10101= -16+4+1 = -11 Addition gives -1 Didn't write other bits because of sign extension 0 0 replyShare Kunal Kadian commented Jan 14, 2019 reply Follow flag Yeah correct. Instead of writing all 32 bits, you can save time by writing only 5 bits, since rest bits are only sign extension and gives the same ans. 1 1 replyShare Abhisek Tiwari 4 commented Jan 14, 2019 reply Follow flag yes -1 is ans. @Kunal Kadian i did nt get it. how it effect the problem result?? @prashant jha 1 "Didn't write other bits because of sign extension" ? 0 0 replyShare Kunal Kadian commented Jan 14, 2019 reply Follow flag @Abhisek Tiwari 4 10 is ==> 00000000000000000/00000000001010 ~10 ==> 11111111111111111111111111110101 ~10 can be simplified to 10101 (chopping extended sign bits) both represents same value i.e. -11 note:- Numbers are stored in 2's complement Representation. 1 1 replyShare Abhisek Tiwari 4 commented Jan 14, 2019 reply Follow flag "Numbers are stored in 2's complement Representation." got it. Thanks @Kunal Kadian @prashant jha 1 @Deepanshu 0 0 replyShare Satbir commented Jan 14, 2019 reply Follow flag why is 10 = 01010 not stored in 2s complement form ?😅 1010 = -8+2 = 6. 0 0 replyShare Kunal Kadian commented Jan 14, 2019 reply Follow flag It is in 2's complement form. In 2's complement form, +ve no's are repreerepre as they are and -ve no's are represented as 2's complement of their positive counterpart. Eg :- -123 will be represented as 2's complement of 123. 86 will be represented as 86 only bcoz its +ve 1 1 replyShare Satbir commented Jan 14, 2019 reply Follow flag please correct me. a= 10;( 00001010) ~a is 1s complement of a i.e. 11110101 we are interpreting ~a as 1s complement but we are taking 2s complement value of ~a when interpreting it as decimal i.e. ~a= 10101= -16+4+1 = -11 why ? because "Numbers are stored in 2's complement Representation." 0 0 replyShare Please log in or register to add a comment.