469,646 Members | 1,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Bitwise NOT

hi
how can i perform a bitwise NOT on a int or long or uint type variable?
so that the bits should be inverted in the result.

-
aamir
Nov 17 '05 #1
2 8251
Try this:

int val = 15;
val = ~val;

See the documentation on the ~ operator:

http://msdn.microsoft.com/library/de...f~operator.asp

Nov 17 '05 #2
Aamir Mahmood <a@b.c> wrote:
how can i perform a bitwise NOT on a int or long or uint type variable?
so that the bits should be inverted in the result.


~ is the bitwise not operator. For instance:

uint x = 0x1234;
uint y = ~x;

y is now 0xffffedcb

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by jas_lx | last post: by
2 posts views Thread by Steve Summit | last post: by
8 posts views Thread by Paul E Collins | last post: by
9 posts views Thread by Christopher Weaver | last post: by
5 posts views Thread by noridotjabi | last post: by
2 posts views Thread by Mark Rae | last post: by
5 posts views Thread by Gigs_ | last post: by
45 posts views Thread by Carramba | last post: by
29 posts views Thread by Carl Banks | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.