Originally Posted by Sarevok kay bored ko, ako ning buhion balik [Programming Language] C/C++ (I think applicable sa tanan) [Question] Recently naay programming question na nisikat sa interwebs which is this: If x is an (binary) integer, what does (x & -x) compute? x & -x returns 1 if bot bits are 1. else 0. for example: x = 15; y = 9; z = x & y; x = 1111 y = 1001 ------------- z = 1001 so x & y yields 9 of decimal 1001. & is bitwise operator.
Originally Posted by Zer0Degree x & -x returns 1 if bot bits are 1. else 0. for example: x = 15; y = 9; z = x & y; x = 1111 y = 1001 ------------- z = 1001 so x & y yields 9 of decimal 1001. & is bitwise operator. sakto imo definition sa bitwise AND operator, pero ang question kay what is x & -x (read x AND two's complement of x)
Originally Posted by Sarevok sakto imo definition sa bitwise AND operator, pero ang question kay what is x & -x (read x AND two's complement of x) i dont get u. if you want to get the binary digit of negative integer, then get it and make an expression of & with a postive x : )
Originally Posted by Zer0Degree i dont get u. if you want to get the binary digit of negative integer, then get it and make an expression of & with a postive x : ) But you missed the main question which is, "What does x & -x compute?". What do you get when you do this operation?
Forum Rules