Why is ~0xF equal to 0xFFFFFFF0?
Also, how is ~0xF && 0x01 = 1? Maybe I don’t get 0x01 either.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Question 1
First, this means you run this on a 32-bit machine. That means 0xF is actually
0x0000000Fin hexadecimal,And that means 0xF is
0000 0000 0000 0000 0000 0000 0000 1111in binary representation.The
~operator means the NOT operation. Tt changes every 0 to 1 and every 1 to 0 in the binary representation. That would make ~0xF to be:1111 1111 1111 1111 1111 1111 1111 0000in binary representation.And that is actually
0xFFFFFFF0.Note that if you do this on a 16-bit machine, the answer of
~0xFwould be0xFFF0.Question 2
You wrote the wrong statement, it should be
0xF & 0x1. Note that0x10x01,0x001, and0x0001are all the same. So let’s change this hexdecimal number to binary representation:0xFwould be:0000 0000 0000 0000 0000 0000 0000 1111and
0x1would be:0000 0000 0000 0000 0000 0000 0000 0001The
&operation follows the following rules:So doing that to every bit, you get the result:
0000 0000 0000 0000 0000 0000 0000 0001which is actually
0x1.Additional
|means bitwise OR operation. It follows:^means bitwise XOR operation. It follows:You can get more information here.