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?

18th Mar 2021, 3:08 PM
Kashyap Kumar
Kashyap Kumar - avatar
1 ответ
+ 2
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)...
18th Mar 2021, 3:39 PM
visph - avatar