• Post Reply Bookmark Topic Watch Topic
  • New Topic

flip 1 & 0  RSS feed

 
Edward Amankwa
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an array of integers with values of 1 & 0 how can I write a method to flip the ones to zero and zero to ones like in c++ bitwise ~ with out using the ~
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... Is this homework?

There's something clever you can do involving Math.abs.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also something you can do with one of the other bitwise operators (besides ~).
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also the - operator.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!