CodeGym /Courses /Java Multithreading /Practice using logical operators

Practice using logical operators

Java Multithreading
Level 10 , Lesson 6
Available

"Hi, Amigo!"

18
Task
Java Multithreading, level 10, lesson 6
Locked
Fork/Join
Fork/Join
9
Task
Java Multithreading, level 10, lesson 6
Locked
Such tricky exceptions!
Such tricky exceptions!
18
Task
Java Multithreading, level 10, lesson 6
Locked
Bit operations
Bit operations
Comments (3)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Evgeniia Shabaeva Level 42, Budapest, Hungary
29 April 2025
The last one was quite something. I needed a lot of extra reading to complete it.
fzw Level 41, West University Place, United States
25 May 2020
One idea for "bit operations", take a random example i = "0..0100101": Step1: right shift i by 1 -> "0..0010010" Step2 : bitwise OR -> "0..0110111" and take this as new i Step3: repeat Step 1 and 2 until all bits after highest "1" bit are all "1", i.e., i should be "0..0111111" Step4 : right shift i by 1 -> "0..0011111" and flip all bits (I'll call this j) Now we have i: 0..0111111 j: 1..1100000 It should be clear by now how to get the highest "1" bit. reference: https://habr.com/ru/post/93172/
BlueJavaBanana Level 37
2 December 2020
Is this allowed? How do you repeat without a loop or without exceeding the size of the number? My single line solution below works but it fails verification because I am using things I am not allowed apparently.

        return Integer.valueOf(1 << (Integer.toBinaryString(number).length() - 1));