1 1 vote int main() { unsigned int x = 1; printf("Signed Result %d \n", ~x); printf("Unsigned Result %ud \n", ~x); return 0; } some one give detailed answer ... (mainly how it works ) Programming in C + – sid1221 1.2k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 2 2 votes Output:- Signed Result = -2 Unsigned Result = (4294967294)10 Explanation:- Now, x = 1 in decimal and in binary 0000 0000 0000 0000 0000 0000 0000 0001 operator ~ is complement of given number. 1's complement of x = 1 --->>> 1111 1111 1111 1111 1111 1111 1111 1110 and its unsigned value is = 4294967294 For signed value use 2's complement notation. Computers uses 2's complement to represent negative numbers. 1111 1111 1111 1111 1111 1111 1111 1110 Representing in 2's complement notation gives -2. Shubhanshu answered Oct 13, 2017 • selected Oct 13, 2017 by sid1221 Shubhanshu comment Share Follow See all 2 Comments 2 2 Comments reply srestha commented Oct 23, 2017 reply Follow flag @ Shubhanshu u mean unsigned number always takes 1's complement representation and signed number always takes 2's complement for a -ve number representation?? 0 0 replyShare joshi_nitish commented Oct 23, 2017 i edited by joshi_nitish Oct 23, 2017 reply Follow flag @srestha C only follows 2's complement representation, it depends on signed or unsigned how that value to be treated... 1 1 replyShare Please log in or register to add a comment.