N
N
Ne0nX2014-01-13 07:56:53
Objective-C
Ne0nX, 2014-01-13 07:56:53

&~ (ampersand with tilda) in Objective-C. How does it work and what happens when this operation is performed?

Recently I saw a construction similar to this one in someone else's code.
int num = 2 &~ 100;
Please explain how it works and what happens when this operation is performed.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Grachev, 2014-01-13
@Ne0nX

I believe that these are bit operations. 2 and (not 100).
To understand what is happening, you need to represent both numbers in binary form.
2: 10, 100: 1100100.
Next, 100 is inverted: 0011011 and the conjunction is made:
11011 & 10 = 00010
As a result, we get 2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question