0
Bit pattern problem
https://code.sololearn.com/cOhF9EhdR6HV/?ref=app The output of ~a and bit pattern of ~a doesn't match, why? And why it's negative always?
2 Answers
+ 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)...
https://www.geeksforgeeks.org/1s-2s-complement-binary-number/