• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does ~ do?  RSS feed

 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't in the book but it is on an enthuware test. I googled and couldn't find the answer.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is called a tilde, to help you google it. It is the bitwise not operator

a = 0b010;
b = ~a;
b == 0b101;
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the unary bitwise complement operator "~". That makes googling a lot easier

It inverts a bit pattern; it can be applied to any of the integral types (not on booleans), making every "0" a "1" and every "1" a "0".

Nice to know: bit-twiddling operators are not on the OCA exam.

Hope it helps!
Kind regards,
Roel
 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Junilu Lacar
Sheriff
Posts: 11433
175
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!