How to swap the first two bits of a number in Scala

1 Answer

0 votes
object Main extends App {
  var num = 162

  println(num.toBinaryString)

  num ^= 1 << 0
  num ^= 1 << 1

  println(num.toBinaryString)
}



   
/*
run:

10100010
10100001
   
*/

 



answered Oct 25, 2024 by avibootz
...