Bit pattern problem | Sololearn: Learn to code for FREE!


Bit pattern problem The output of ~a and bit pattern of ~a doesn't match, why? And why it's negative always?

3/18/2021 3:08:17 PM

Kashyap Kumar

2 Answers

New Answer


sizeof give you size in bytes, while bit pattern should use number of bits (1 byte == 8 bits)... do your bit pattern truncate your binary value to 4 bits, while there's 32 bits ^^ result of 1-complement (~) is negative because the value from wich you get complement is positive... and int are signed values... 1-complement inverse all bits 2-complement is 1-complement + 1 later is how are handled signed binary (left most bit determine sign, other bits determine value in a way that you get corrects mathematic result by using those values)...